Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

how to set a Default value inside an Reference component provided using data-sly-resource

Avatar

Level 3

hi ,

 

I have a component which uses an reference component embedded inside the main component. I am using AEM 6.5 . 

<sly data-sly-resource="${'experiencefragment' @ resourceType='cq/experience-fragments/editor/components/experiencefragment'}"></sly>

I need to define default values to the fragmentPath inside the experience fragment. I tried using the approach provided under 

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/default-value-in-reference... , i.e using cq:template and cq:templatePath approach and it fails . 

 

STEPS : 

1. Created a node inside the component of type nt:unstructured called cq:template. Added a property called fragmentPath of type String to it with default value for XF path. 

2. Created a sling:folder outside the component called templateConfigs, created node of type nt:unstructured inside it called experienceFragment . Added a property to it called fragmentPath of type String. Then added a property to component called cq:templateType (String) and added path of the new config as its value.

 

Both above approaches did not work. Please help.

 

Thanks,

Samiksha,

 

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi @samikshaa223429,

@arunpatidar beat me to the punch  But his answer is correct! One thing to know is that the value is cq:template are set when a component is created. That means if you placed your component on the page, then modified the cq:template values, you would have to remove and add the component again to see the changes, maybe that is your problem? 

Other things to look out for:

  • The cq:template child must have the same name as the name of the resource in your data-sly-resource attribute (ie: experiencefragment)
  • The property you want to set a default for must match the name of that property in the target resourceType (ie: fragmentPath)

Here's a quick GIF to prove it works:

Peek 2020-07-01 12-45.gif 

View solution in original post

7 Replies

Avatar

Community Advisor

Create a node inside the component of type nt:unstructured called cq:template. Add a child node experiencefragment type of nt:unstructured and add a property called fragmentPath of type String to it with the default value for XF path. 



Arun Patidar

Avatar

Level 3

hi Arun ,

 

The solution shared by you didnt work . XF is still not picking up the default value. 

Avatar

Correct answer by
Level 10

Hi @samikshaa223429,

@arunpatidar beat me to the punch  But his answer is correct! One thing to know is that the value is cq:template are set when a component is created. That means if you placed your component on the page, then modified the cq:template values, you would have to remove and add the component again to see the changes, maybe that is your problem? 

Other things to look out for:

  • The cq:template child must have the same name as the name of the resource in your data-sly-resource attribute (ie: experiencefragment)
  • The property you want to set a default for must match the name of that property in the target resourceType (ie: fragmentPath)

Here's a quick GIF to prove it works:

Peek 2020-07-01 12-45.gif 

Avatar

Community Advisor
Yes you are correct @Theo_Pendle , the cq:template's properties are added to the node as soon as component added to the page. The idea to have properties in cq:template to initialize component with default values similar to value property of Granite field type. Once the component is modified or already added, cq:template will not have any effect.


Arun Patidar

Avatar

Level 3
hi , the issue is that I am not using this inside a component(which is dragged into a parsys). It gets loaded on the page creation and is added in template html

Avatar

Community Advisor
Hi, You need to add cq:template to the page component if you are using static template otherwise you need to add default node and properties in the initial part of dynamic template.


Arun Patidar