Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

gettting path of CSS / JS from clientLib category name programatically

Avatar

Level 4

Hi all,

 
Hope everyone is doing fine !
 
In JSP usually if we have to include clientLib then we use below statement
<cq:includeClientLib js="personalization.ui"/>
 
And then these gets translated to actual script tags
<script type="text/javascript" src="/etc/clientlibs/personalization.js"></script>
 
Is there any way to get the path of JS referred by the clientLib category name using code ?
 
ie., I pass "personalization.ui" and it returns me back "/etc/clientlibs/personalization.js"
 
We have to do some further processing on this JS path so we need this.

 

Thanks in advance.

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

You can use the HtmlLibraryManager API to get the path of the JS from the client lib name.  

First get the ClientLibrary by passing the category name in the below API method-

https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/com/day/cq/widget/HtmlLibraryManager.html#getLibrari...

And then get the include path of the JS by calling the following API method-

https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/com/day/cq/widget/ClientLibrary.html#getIncludePath(...

View solution in original post

4 Replies

Avatar

Level 10

Can you share your use case.....I mean what you are trying to achieve using JS Path?

Avatar

Level 4

Hi edubey,

Thanks for looking into it.

We need to pass the JS path to resource resolver to get final JS path

resourceResolver.map(request,jsPath) 

Avatar

Level 10

If these are your client library then you already know where they exist and there position will not change (unless you forcefully do) and if there are OOTB, their location will never be changed.

If would be great, if you can provide more insight of use case...

Avatar

Correct answer by
Employee Advisor

You can use the HtmlLibraryManager API to get the path of the JS from the client lib name.  

First get the ClientLibrary by passing the category name in the below API method-

https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/com/day/cq/widget/HtmlLibraryManager.html#getLibrari...

And then get the include path of the JS by calling the following API method-

https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/com/day/cq/widget/ClientLibrary.html#getIncludePath(...