Defaults in your CQ5 component
When you have read my post around default components in your parsys then if you take it a step futher you want to have also defaults at component level.
In this post I will take the Text & Image component and will make the following changes when you drag this component onto your page:
- There is already a default text
- An image is already pre-filled
We start by using the Text & Image component in a content page and specify a value for the Text and drop an image in the component.
I have used one of the default images from the Geometrixx application.
After you added the component to the page and the values are specified, go to CRXDELite and look at the nodes created for the Text & Image component.
You see a "textimage" node with a childnode called "image" where the image details are stored. At the level of "textimage" the text is specified.
Before we can make any changes we will overlay the default Text & Image component, this is located in /libs/foundation/components/textimage.
Create a folder structure "foundation/components" in the "apps" folder and copy the default component in that location.
Ok, here comes the trick. Create a node cq:template of the type nt:unstructured under your component.
In the node add the two properties from the "textimage" node
- "text", value "<p>This is some text</p>"
- textIsRich, value "true"
Now copy the "image" node (from the contentpage) so that is a child of the cq:template node.
To test the changes make sure you have saved the newly created nodes and you have refreshed the content page.
When you now drag/drop the Text & Image component on your page you see it contains a default text and a default image.
This all done by creating nodes, not by coding!
Feike Visser (twitter: @heervisscher)