Fetch data from CF and store in teaser | Community
Skip to main content
Level 2
June 29, 2022
Solved

Fetch data from CF and store in teaser

  • June 29, 2022
  • 2 replies
  • 704 views

How I can fetch data that is stored in content fragment and show them in teaser?
For example in CF I have A,B,C,D fields and in teaser I just need A,B so teaser need to by dynamically populated based on CF?
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 arunpatidar

Hi,

Content fragment stored data in a node as properties. YOu can simply read those properties in Teaser component.

 

Example - https://github.com/arunpatidar02/aemaacs-aemlab/blob/master/ui.content/src/main/content/jcr_root/content/dam/aemlab/cf/teaser-example-1/.content.xml 

 

  1. Create a pathfield in the component dialog to browse CF.
  2. Parse the CF nodes and read A, B properties.

 

https://aemlab.blogspot.com/2018/09/aem-content-fragment-with-component.html

2 replies

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
June 29, 2022

Hi,

Content fragment stored data in a node as properties. YOu can simply read those properties in Teaser component.

 

Example - https://github.com/arunpatidar02/aemaacs-aemlab/blob/master/ui.content/src/main/content/jcr_root/content/dam/aemlab/cf/teaser-example-1/.content.xml 

 

  1. Create a pathfield in the component dialog to browse CF.
  2. Parse the CF nodes and read A, B properties.

 

https://aemlab.blogspot.com/2018/09/aem-content-fragment-with-component.html

Arun Patidar
ShaileshBassi
Community Advisor
Community Advisor
June 29, 2022

@stefanjank  Steps:

1. Adapting a resource to Content Fragment.
2. Once we adapt to Content Fragment we get the object of CF which give the content fragment name i.e contentFragmentName.
3. Once we get the content fragment object, we can get all the properties associated with that content fragment (master node) by creating an iterator on CF object of type ContentElement.
4. We can iterate on the contentElement and get the property name in tagElement and it’s content in elementContent in above created variables.

 

The above code snippet provides details only related to the master of the content fragment. To get the details of the variations we can use the below API and the elements and other details:

Iterator<VariationDef> variationIterator = cf.listAllVariations();
while (variationIterator.hasNext()) {
String variationName = variationIterator.next().getName();
}

I suggest to refer below reference link to explore more API provided by Content Fragment Interface.

https://helpx.adobe.com/experience-manager/6-4/sites/developing/using/reference-materials/javadoc/com/adobe/cq/dam/cfm/ContentFragment.html

 

Thanks