How I can include xf directly (not through parsys) in aem component through sightly | Experience Fragments | HTL | Community
Skip to main content
Abhishekty
Level 4
Jul 5, 2022 7:42 PM UTC
Solved

How I can include xf directly (not through parsys) in aem component through sightly | Experience Fragments | HTL

 

Can I include xf directly on the AEM component through Sightly?

 

For ex:

 

this is existing code: 

 <sly data-sly-test=${currentStyle.myFlag}>
data-sly-resource="${ @9556322='myContent', resourceType='/apps/my-common/components/content/mycomponent'}"
data-sly-unwrap="${!wcmmode.edit}"></div>
</sly> 

 

But now I have created an xf for mycomponent and now I want to directly use it on the AEM component.

 

Like: 

 

 <sly data-sly-test=${currentStyle.myFlag}>
data-sly-resource="${ @9556322='myXf', resourceType='content/experience-fragments/sprint/shared/mycomponentXF'}"
data-sly-unwrap="${!wcmmode.edit}"></div>
</sly> 

 

Can anyone suggest is this possible or a good approach?

Manu_Mathew_
Manu_Mathew_Accepted solution
New Participant
Jul 7, 2022 2:36 PM UTC

@abhishekty 

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>

 

2 replies

Manu_Mathew_
Manu_Mathew_Accepted solution
New Participant
Jul 7, 2022 2:36 PM UTC

@abhishekty 

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>

 

Translate
SantoshSai
New Participant
Jul 5, 2022 7:52 PM UTC

Hi @abhishekty ,

Try this,

<sly data-sly-resource="${@path='content/experience-fragments/sprint/shared/mycomponentXF',
   selectors='content', wcmmode='disabled'}"></sly>

Hope that helps!

Regards,

Santosh

Translate
Santosh Sai