Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

How to add an Experience Fragment to existing 150 pages without authoring/editing page and roll out pages ?


Level 2

I have the situation where want to add an Experience Fragment (having button component) to under image component without authoring/editing and roll out all pages. These pages following same template.

4 Replies


Community Advisor

Hi @csaini ,

The best plausible approach would be to add through HTL, if it works.

Hard Coded Example
The first example uses sightly to reference an experience fragment, /content/experience-fragments/we-retail/equipment, and the required variation, master. This will only work when the path includes the experience fragment variation path. The value here is hard coded.

<sly data-sly-resource="${@path='/content/experience-fragments/we-retail/equipment/master',
   selectors='content', wcmmode='disabled'}"></sly>

Dynamic Example

In the second example, we can see that our component adapts to the com.mysite.models.component.MyCustomComponent, Sling Model backend, and then it exposes the experience fragment in the exPath property. The value returned from the exPath is ‘/content/experience-fragments/we-retail/equipment/master’.

<sly data-sly-use.cmp="com.mysite.models.component.MyCustomComponent"></sly>
<sly data-sly-resource="${@path=cmp.exPath,
   selectors='content', wcmmode='disabled'}"></sly>
Reference: https://sourcedcode.com/blog/aem/dynamically-include-an-experience-fragment-in-sightly
Hope that helps!


Level 2

Firstly, thank you for the quick response.


I have a follow up question - my Experience Fragment is based on language copy such as "en-US", "ja-JP", "de-DE" etc.




How to deal exPath in this situation dynamically when page render as JP domain or other domain.
Thanks for the help in advance!



Level 4

If you are working on an Editable template then you can edit it and place new content in structure or initial content section.


Level 2

In my case, each page have around 10 components ( banner, text, image, accordion etc) already on the page those are rendering as normal component not as structure or initial. I want to add Experience Fragment below the image component without authoring or roll out page.