Include Component in JSP in AEM | Community
Skip to main content
Level 2
July 4, 2022
Solved

Include Component in JSP in AEM

  • July 4, 2022
  • 4 replies
  • 3354 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by sravs

@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"/>

4 replies

sravs
Community Advisor
sravsCommunity AdvisorAccepted solution
Community Advisor
July 4, 2022

@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"/>
Sachin_Arora_
Community Advisor
Community Advisor
July 4, 2022

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

Pallavi_Shukla_
Community Advisor
Community Advisor
July 4, 2022

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=en

<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.

 

 

Aditya_Chabuku
Community Advisor
Community Advisor
July 5, 2022

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