Dynamically adding an existing content fragment to a custom component | Community
Skip to main content
New Participant
December 15, 2022
Solved

Dynamically adding an existing content fragment to a custom component

  • December 15, 2022
  • 2 replies
  • 1322 views

I've been tasked with adding an existing content fragment to a custom component. The path to the content fragment is populated by a custom page property a content author would add. I need to use that value in a custom component that includes the dynamic call to the content fragment. All I can find in the way of examples is adding a content fragment directly to a page. Does anyone have an idea of where I can get examples of how this is done? Thanks!

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 nitesh_kumar-1

Hi @gfuller-crescendo 

You could make use of the Sling model of the custom component.

1.) Resolve the CF using the path retrieved from page properties (authored).

2.) Use CF API to adapt to the content fragment.

3.) Set the Sling model object with values that can be read on HTL

you can refer to this one

https://aem4beginner.blogspot.com/fetch-content-fragment-using-sling-model 

 

Alternatively, if it's a front-end-based logic then you can make use of HTTP Asset API to fetch the CF details in JSON format and bind it to the UI at Front-end.

https://experienceleague.adobe.com/docs/experience-manager-65/assets/extending/assets-api-content-fragments.html?lang=en

 

Regards,

Nitesh

 

2 replies

arunpatidar
New Participant
December 16, 2022

I also tried something long back,  https://aemlab.blogspot.com/2018/09/aem-content-fragment-with-component.html

Although its an outdated solution, you can take inspiration from there

Arun Patidar
nitesh_kumar-1
nitesh_kumar-1Accepted solution
Employee
December 15, 2022

Hi @gfuller-crescendo 

You could make use of the Sling model of the custom component.

1.) Resolve the CF using the path retrieved from page properties (authored).

2.) Use CF API to adapt to the content fragment.

3.) Set the Sling model object with values that can be read on HTL

you can refer to this one

https://aem4beginner.blogspot.com/fetch-content-fragment-using-sling-model 

 

Alternatively, if it's a front-end-based logic then you can make use of HTTP Asset API to fetch the CF details in JSON format and bind it to the UI at Front-end.

https://experienceleague.adobe.com/docs/experience-manager-65/assets/extending/assets-api-content-fragments.html?lang=en

 

Regards,

Nitesh