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

Adding attributes to script tag, for ClientLibrary includes

Avatar

Level 2

 I would like to continue adding client library files to JSPs as follows:

  <cq:includeClientLib js="some-category" />

But I need to have control over the attributes in the resulting script include. In other words I might want to see

<script type="application/javascript" async defer data-attr="somedata" src="<path to clientlib.min.js></script>

I have not seen any document that explains how to achieve this. I was hoping for something similar to adding classes for cq:htmlTag. Clearly I could do this manually by adding the script tag myself, and manually adding the path to the clientlib, but then I lose the ability to reference by category, which is my major use case for using clientlibs.

Thanks,

Matt

1 Accepted Solution

Avatar

Correct answer by
Employee

Hi Matt,

There's no way to change the HTML output by <cq:includeClientLib>. Rather you need to create your own tag which uses the HtmlLibraryManager to get the list of includes for a particular category (or set of categories) and use those to output the appropriate HTML.

What you describe with something like cq:htmlTag seems like a worthwhile enhancement. I'd suggest filing a DayCare issue with the details so that this can be added to the product roadmap.

Regards,

Justin

View solution in original post

2 Replies

Avatar

Correct answer by
Employee

Hi Matt,

There's no way to change the HTML output by <cq:includeClientLib>. Rather you need to create your own tag which uses the HtmlLibraryManager to get the list of includes for a particular category (or set of categories) and use those to output the appropriate HTML.

What you describe with something like cq:htmlTag seems like a worthwhile enhancement. I'd suggest filing a DayCare issue with the details so that this can be added to the product roadmap.

Regards,

Justin

Avatar

Level 2

Hi Justin,

Thanks for your help with this, much appreciated. I'll create the tag and use HtmlLibraryManager as you suggest.

I think adding a String[] property to accept various attribute value pairs would be a very helpful addition (or something similar). I'll create a DayCare issue.

Thanks again,

Matt