Monday 2 February 2015

Themes in clientlibs to include specific resources AEM6/CQ5

Hi Guys,

As we know, clientlibs in CQ5 use to include our js/css files via one line of code in our script file apart from other benefits. One thing that i had in my mind is what would be the case, If I want to add only few JS files via my <cq:includeClientLib />. Now got the answer which is might not be the full proof but yes, fulfill the aim of a developer. Answer is via Themes.

Use-Case : Have 3 JS files alpha.js,beta.js,gamma.js. I have Clientlib with category themetest. So with <cq:includeClientLibs /> how can i selectively inject the js files inside my script file.

Below demonstration will exaplin you how :

1) Create a clientlibrary folder with name say clientlibtest with categories themetest.
2) Create js folder and add two file say alpha.js & beta.js inside it.
3) Register their entries in js.txt file.
4) create a folder named themes under your clientlibtest folder.
5) Create a clientlib folder with any name say themegamma, keep the categories of themegamma should be same as clientlibtest i.e themetest
6) Create js folder under themegamma and add file say gamma.js inside it.
7) Register its entry in js.txt file which you created inside themegamma.

Below is the snapshot :




Now if you write the statement:

<cq:includeClientLib js="themetest" themed="true"/>
In that case only gamma.js will gets load.

<cq:includeClientLib js="themetest" themed="false"/>
In that case alpha.js & beta.js files will gets load.

<cq:includeClientLib js="themetest"/>
In that case all of js files will gets load.


Hope this will help.

Thanks

No comments:

Post a Comment