Expand my Community achievements bar.

Applications for the 2024-2025 Adobe Experience Manager Champion Program are open!
SOLVED

Dynamically adding an existing content fragment to a custom component

Avatar

Level 1

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!

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

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

 

Regards,

Nitesh

 

View solution in original post

2 Replies

Avatar

Correct answer by
Employee Advisor

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

 

Regards,

Nitesh

 

Avatar

Community Advisor

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