April 2, 2020
Estimated Post Reading Time ~

Import JSTL Custom tags to Adobe CQ5

Steps to add JSTL 2.0 custom tags to Adobe CQ5:

1. Create custom tag
Create your own custom tag at location say /apps/myproject/taglibs/foo.tag and the contents of the tag are as below:

<%@ attribute name="greeting" required="true" %>
<%@ attribute name="name" required="true" %>
<h1>Im a custom taglib [${greeting}, ${name}]</h1>

2. Use tags in a html or jsp page:
To use Custom Tag Lib Files within CQ5 and you can just add a tag file somewhere on the JCR and reference it via

<%@ taglib tagdir="/WEB-INF/tags/apps/myproject/taglibs" prefix="ctags" %>
<ctags:foo greeting="Hello" name="CQ User"/>
Note that the “/WEB-INF/tags/” need to be prefixed the path where the tag libs exist.

3. Add below code to the maven-assembly plugin
<assembly>
....
<filesets>
<fileSet>
<directory>src/main/content/jcr_root</directory>
<outputDirectory>jsp-dependencies/jcr_root/WEB-INF/tags</outputDirectory>
<includes>
<include>**/*.tag</include>
</includes>
</fileSet>
</filesets>
....
</assembly>  

The output directory filter needs to be created for the tag as the custom tags need to be copied from /apps/myproject/taglibs to WEB-INF/tags/apps/myproject/taglibs.



By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.