Expand my Community achievements bar.

SOLVED

Content Fragment Variation in sling model

Avatar

Level 6

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

}

 

View solution in original post

4 Replies

Avatar

Level 1

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();}

Avatar

Level 6

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

Avatar

Community Advisor

@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-ap... 

Avatar

Correct answer by
Community Advisor

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

}