Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Include Component in JSP in AEM

Avatar

Level 2

Dear All,

 

I have one simple component called testcomponent under apps/test/components/testcomponent

 

Now I want to include content fragment component inside the testcomponent.jsp..How can I include my content fragment component in my JSP.

 

Thanks in advance

Haritha

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@haritha6 ,

 

You can use cq:include to include a resource/component into your jsp as below.

 

<cq:include path="test" resourceType="my-site/components/test-component"/>

View solution in original post

4 Replies

Avatar

Correct answer by
Community Advisor

@haritha6 ,

 

You can use cq:include to include a resource/component into your jsp as below.

 

<cq:include path="test" resourceType="my-site/components/test-component"/>

Avatar

Community Advisor

First of all I would suggest you to please use HTL instead of JSP.

Answering your question : You can include HTML file in your JSP (<cq:include script="include.html"/> ) and write all code using sightly. You can use cq:template to include CF component inside your component. It will add node when you add component in Page. In HTL, you can use data-sly-resource for CF component.
Refer We-Retail Code : /apps/weretail/components/structure/footer/cq:template & /apps/weretail/components/structure/footer/footer.html

Avatar

Community Advisor

hi @haritha6 

 

The below doc gives you all the syntax to include tag libraries in JSP.

The Granite, CQ, and Sling tag libraries give you access to specific functions for use in the JSP script of your templates and components.

https://experienceleague.adobe.com/docs/experience-manager-64/developing/platform/taglib.html?lang=e...

<cq:include>

The <cq:include> the tag includes a resource on the current page. I think that would suffice your content fragment use case too.

 

 

Avatar

Community Advisor

Hi @haritha6 ,

 It seems like you are trying to implement Content Fragment into your component.

for that, try to implement Content Fragment component from core components into your project by  

sling:resourceSuperType = /core/wcm/components/contentfragment/v1/contentfragment.

change jsp to HTML & write your custom HTL as required.

 

OR  if your requirement is to include a Content Fragment into your existing jsp component, then use <cq:include>  as others said.

 

~Aditya.Ch

Thanks,

Aditya Chabuku