Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

cq:templatePath and cq:template behaviour

Avatar

Level 3

When both cq:templatePath and cq:template are set on component, cq:templatePath configuration are only picked up. Is it expected behaviour?.

 

Details: (cq:template)

in _cq_template.xml 

<?xml version="1.0" encoding="UTF-8"?>

<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0"  xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"

    jcr:primaryType="nt:unstructured"

    firstname="FirstName via cq:template"

    lastname="LastName via cq:template"

    >

</jcr:root>

 

Details: (cq:templatePath)

cq:templatePath="/apps/samplehtl/components/content/include/templatepath"

 

In folder of /apps/samplehtl/components/content/include

<?xml version="1.0" encoding="UTF-8"?>
jcr:primaryType="sling:Folder">
<templatepath
jcr:primaryType="nt:unstructured"
firstname="FirstName via cq:templatePath"
lastname="LastName via cq:templatePath"
>
</templatepath>
</jcr:root>
 
Out put is :
FirstName via cq:templatePath
LastName via cq:templatePath
 
In folder of /apps/samplehtl/components/content/include -- remove LastName
<?xml version="1.0" encoding="UTF-8"?>
jcr:primaryType="sling:Folder">
<templatepath
jcr:primaryType="nt:unstructured"
firstname="FirstName via cq:templatePath"
>
</templatepath>
</jcr:root>
 
Out put is :
FirstName via cq:templatePath
 
I have set missed paramter lastname in cq:template, it is not using configuration (from cq:template) for that value.It is always using cq:templatePath for all paramter.is it expected behaviour(cannot mix both cq:template and cq:templatePath)?
 
 
 

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Dillibabu77, this is correct and expected behavior that cq:templatePath is used when both cq:template and cq:templatePath are configured.

To better understand that relation between cq:templatePath and cq:template, you can think of it this way. If you have cq:tamplate configured then it is like cq:templatePath point to your specific component cq:tamplate definition. When you set cq:templatePath value explicitly then it can point to any location, also outside definition of your component. That also means that if your cq:templatePath is configured than cq:template will not be take into account, unless cq:templatePath is point to it (but in that case you probably do not need cq:templatePath at all)

View solution in original post

4 Replies

Avatar

Community Advisor

Hi @Dillibabu77 

 

cq:template: This is a node having cq:template name of type nt:unstructured inside a component. The use case for this property can be if you want to provide the default values of properties of a component, then it can help you out. cq:template node can have multiple properties and even other nodes as a children in case if you need to aggregate some of the properties (i.e., name = ./name/title).This content will be used as default values whenever you drop a new instance of the component from the sidekick. If found, this node will be used as a content template when the component is added from the Components Browser or Sidekick.

 

cq:templatePath: This property is of type string. If you want to share the same default values across multiple components, you can create a node with any name, put all the properties there and add the path of that node as a value in the cq:templatePath property. It works exactly like cq:template but with the help of cq:templatePath, the same values can be shared across multiple components.

 

When an author drops the component, the component fetches all the values from its templatePath or cq:template node (cq:templatePath takes precedence over cq:template) and store them in the /content hierarchy of that component. When author opens the dialog, the values can be seen there. If the author wants to change, they can also do that.

 

Path to a node to use as a content template when the component is added from the Components browser or Sidekick. This must be an absolute path, not relative to the component node. Unless you want to reuse content already available elsewhere, this is not required and cq:template is sufficient

 

For More details please refer the below link:

https://experienceleague.adobe.com/docs/experience-manager-64/developing/components/components-basic...

 

Thanks!

 

Avatar

Correct answer by
Community Advisor

Hi @Dillibabu77, this is correct and expected behavior that cq:templatePath is used when both cq:template and cq:templatePath are configured.

To better understand that relation between cq:templatePath and cq:template, you can think of it this way. If you have cq:tamplate configured then it is like cq:templatePath point to your specific component cq:tamplate definition. When you set cq:templatePath value explicitly then it can point to any location, also outside definition of your component. That also means that if your cq:templatePath is configured than cq:template will not be take into account, unless cq:templatePath is point to it (but in that case you probably do not need cq:templatePath at all)