Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

Core WCM Experience Fragment Sling Model - Modify Response to Output Content of a Different XF Variation

Avatar

Level 1

I am using core wcm Experience Fragment (com.adobe.cq.wcm.core.components.models.ExperienceFragment) which I am extending in my own code base via the @Delegate pattern. When author adds an experience fragment on a page / when request is made to export the XF as json, I need to check all variations of given XF, filter them based on tag and export one of the variations which matches my tag as JSON. How can I rewrite the current request to generate the content of a XF variation in the sling model?

 

I am able to get paths of all variations from given XF but when I try to adaptTo(ExperienceFragment.class) it is always null. I can adaptTo(ValueMap.class) from which I can see the template used by that variation but that is not helpful as that does not give me exported items. I tried creating a new temporary page using PageManager from given XF template however running into replication errors that way.

 

Is there a way to export an XF variation of our choosing in Sling model when request is made for a different variation of the same XF?

 

I noticed there's a private getChildren() method on the core XF which is used to get all exported items and which relies on getLocalizedFragmentVariationPath() method in the same core XF class but even if I override the getLocalizedFragmentVariationPath method to return path of a different variation the JSON items exported are those of the original experience fragment, not the modified variation.

 

Any help would be massively appreciated.

1 Accepted Solution

Avatar

Correct answer by
Administrator

To modify the response to output the content of a different XF variation, you can override the getLocalizedFragmentVariationPath() method in your custom Sling model class. This method is responsible for returning the path to the localized fragment variation for the current request. By overriding this method, you can return the path to the variation that you want to output, regardless of the variation that was originally requested. By overriding the getLocalizedFragmentVariationPath() method in this way, you can effectively rewrite the current request to generate the content of the desired XF variation.



Kautuk Sahni

View solution in original post

1 Reply

Avatar

Correct answer by
Administrator

To modify the response to output the content of a different XF variation, you can override the getLocalizedFragmentVariationPath() method in your custom Sling model class. This method is responsible for returning the path to the localized fragment variation for the current request. By overriding this method, you can return the path to the variation that you want to output, regardless of the variation that was originally requested. By overriding the getLocalizedFragmentVariationPath() method in this way, you can effectively rewrite the current request to generate the content of the desired XF variation.



Kautuk Sahni