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!
Solved! Go to Solution.
Views
Replies
Total Likes
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.
Regards,
Nitesh
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.
Regards,
Nitesh
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
Views
Likes
Replies