Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between the cq:template and cq:templatePath properties in an AEM component?

Tags:

aem

Components in AEM 6.0 can have the properties: cq:template and cq:templatePath. As I am working not both are required always but I don't get the exact difference between these two.

like image 619
anubhs Avatar asked Dec 25 '22 12:12

anubhs


1 Answers

cq:template

cq:template has the type nt:unstructured, it allows you to define a complex node with a set of properties and children. It's a node you create as a child of your component definition. This content will be used as default values whenever you drop a new instance of the component from the sidekick.

Here's an example. componentA has a child called cq:template of the type nt:unstructured. The cq:template node can have multiple properties and even other nodes as children in case if you need to aggregate some of the properties. Here's how it would look in CRXDE

Use of cq:template

cq:templatePath

cq:templatePath has the type String, it's a simple property, the value of which allows you to point to a node much like one you'd create when using cq:template, except it's located elsewhere. Just set it to the path of the node that you want to use as the actual content template definition.

If there's a common pattern in the content used by multiple components, you can define the template in a single place and use cq:templatePath to reuse it. If the content is specific to a single component, define it using cq:template

Here, cq:templatePath is just a property of the node corresponding to the componentA component. Its value points to a different node in the repository that contains the actual content to be used as the template. The structure of the other node is the same as in the previous example.

Use of cq:templatePath

You can find more information in the documentation

like image 163
toniedzwiedz Avatar answered May 29 '23 03:05

toniedzwiedz