content-management-systemadobeaemwcm

Why exactly templates are needed in CQ?


Why exactly do we need templates when all a template does is to have a resourceType property attached to a content-page component.

At the time of creating new page, shouldn't authors directly select that component instead?


Solution

  • The template nodes define the metadata for the page that will be created, one aspect of which is the underlying resource type (i.e. the Page component that will be used to render out the content).

    Some example of other things configured at a template level include:

    1. The default content that is included when the page is created. This is stored under the template node itself, i.e. in /apps/[your-site]/templates/homepage.

      For example, you could add a carouselnode underneath the homepage node, to ensure that any page created with the homepage template will have a carousel node added by default.

    2. The allowed parents & children of the template — e.g. configuring the homepage template so that it can't be placed beneath other templates.

    3. The allowed components in each parsys — In /etc/designs/[your-design]/jcr:content, you can defined what components can be added to a particular parsys, which applies to any page using that template.

    By having a separation between templates & page components it allows us to re-use the same renderers (e.g. JSP scripts), but have aspects like these configured differently for different templates.