Content Fragment Variation in sling model | Community
Skip to main content
Level 6
March 24, 2023
Solved

Content Fragment Variation in sling model

  • March 24, 2023
  • 1 reply
  • 1524 views

I want to fetch the data from the different variation of content fragment in my java class. I am using Content Fragment API.

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 Saravanan_Dharmaraj

Also noticed while looping thru contentElement

Iterator<ContentElement> contentElement = cf.getElements(); while(contentElement.hasNext()){ ContentElement contentElementObject = contentElement.next(); ContentVariation cv = contentElementObject.getVariation(variationName); // get variation names early String contentText = cv.getContent(); // This gives variation's content for that element }

 

1 reply

Saju-Sam
March 24, 2023

To list all variations of a CF

Iterator<VariationDef> variationIterator = cf.listAllVariations(); -  

 

 Iterate the contents inside CF.

 Iterator<ContentElement> contentElement = cf.getElements();  
 ContentElement contentElementObject = contentElement.next();
  String tagElement = contentElementObject.getName().toString();}

Level 6
March 24, 2023

I need variation content and not just the list of variation. Iterator<VariationDef> variationIterator = cf.listAllVariations(); this is not helping as the iterator is of type variationDef.

Your second code snippet also won't help because the content element is of master and i need elements of other variations

Saravanan_Dharmaraj
Community Advisor
Community Advisor
March 24, 2023

@shaheena_sheikh One suggestion could be use get the name using VariationDef and make a call to Graph QL and get the elements since VariationDef API gives very basic metadata not the elements.

 

Example below to get the elements of variation using Graph QL

https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/headless/graphql-api/sample-queries.html?lang=en#Sample%20Query%20-%20All%20Cities%20with%20a%20Named%20Variation