Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

Sling model to retrieve data from content fragments.

Avatar

Level 2

How to create a sling model which can fetch values from content fragments?

2 Replies

Avatar

Level 2

@Jitesh07 

Not sure what your use case is or what exactly you need to achieve at the end.

 

- If you simply need to map some Sling model over some CF, then you need to look at this as like you would map a Sling model on any other Sling resource. Is the same approach. You write a Sling model, you add your Java properties mapping your CF properties, and you give it a path to read from /content/dam/path/to/your/cf/jcr:content/data/... And the example provided by @arunpatidar are more then enough.

 

- If your use case is more about having a way to get CF data in JSON format to consume it in other place, not directly in a Sling model, maybe you can consider exploring other 2 options (JSON Exporter and GraphQL) explained in this thread https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/how-to-get-data-from-conte...