Attimes we come across a situation while creating Components in CQ/AEM, where we want a default value of some property to be set the moment component is dropped. This can be done via JCR API but there is an easy way that I will cover in this post.
Using cq:template node :
Simply create a node under component node with name "cq:template" of type "nt:unstructured".
Now add any property on this node you want to set as default value on the component. Not only properties you can even add node under this node if you want to create a default node under the component node.
And Its done. Now every time you drop this component on any page, default values will be created under the component node as shown below :
Here is link to code repository for this component : https://github.com/ankit-gubrani/Codebrains/commit/eea7cc35ae9c736e7ac4d39b398a37f9e5939b88
Using cq:template node :
cq:template node |
Simply create a node under component node with name "cq:template" of type "nt:unstructured".
Now add any property on this node you want to set as default value on the component. Not only properties you can even add node under this node if you want to create a default node under the component node.
Component node hierarchy under /apps |
And Its done. Now every time you drop this component on any page, default values will be created under the component node as shown below :
Final node hierarchy under /content |
Here is link to code repository for this component : https://github.com/ankit-gubrani/Codebrains/commit/eea7cc35ae9c736e7ac4d39b398a37f9e5939b88