Hi Team,
I've multiple sites on my AEM instance with same page structure but different CSS, I want those pages to be created from single template but not sure how to include different css as per site.
E.g. I've three sites A, B, C with css as a.css, b.css & c.css
Template is generic with code as :
<sly data-sly-use.clientLib="${'/libs/granite/sightly/templates/clientlib.html'}">
<clientlib data-sly-call="${clientLib.css @ categories=['clientlibs.a']}" />
Above code works fine for A site, but for B & C I want the css to be changed dynamically.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi,
Since you want to include different clientlib as per different sites, you can keep a page property where you can select whether you are creating the page for site A or B or C, Then using this property you can make conditional include in html for clientlib using data-sly-test
Or
have base template where you keep a file clientlib.html which basically includes clientlib A , now create other two templates both having sling:resourceSuperType to first template .Now In these two template do nothing just keep a file clientlib.html having inclusion of B and C clientlib respectively.
If you want, I can explain these approaches in detail.
Hope this helps!
Thank you!
Nupur
Views
Replies
Total Likes
Hi,
In your template have a conditional statement to check the route site and include the library accordingly.
Thanks,
Views
Replies
Total Likes
Hi,
Since you want to include different clientlib as per different sites, you can keep a page property where you can select whether you are creating the page for site A or B or C, Then using this property you can make conditional include in html for clientlib using data-sly-test
Or
have base template where you keep a file clientlib.html which basically includes clientlib A , now create other two templates both having sling:resourceSuperType to first template .Now In these two template do nothing just keep a file clientlib.html having inclusion of B and C clientlib respectively.
If you want, I can explain these approaches in detail.
Hope this helps!
Thank you!
Nupur
Views
Replies
Total Likes
Also you can use the design-path for this.
${currentDesign.path}/css/home.css (for example).
If you have a different design configured the path will change.
Views
Replies
Total Likes
Thanks Nupur for your reply, this was one of the way to resolve this issue but my issue was bit more complex as my site was already live and hence on a live page your template property changes wont reflect until unless you modify that page.
Hence, I've created a simple class which reads all css/js etc from a flat file, that flat file has enteries like this A_clientlibs = "1,2,3,4" , B_clientlibs= "2,3,5,6"
So, it was quite easy for my class to pick project wise clientlibs and then putting it in my sightly code.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies