Wednesday, 10 December 2014

Default vaules with CQ5/AEM component

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 :

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 :