How Templates are structured

There are two aspects to be considered:

  • the structure of the template itself
  • the structure of the content produced when a template is used

The structure of a Template

A Template is created under a node of type cq:Template.

screen_shot_2012-02-13at63646pm

Various properties can be set, in particular:

  • jcr:title - title for the template; appears in the dialog when creating a page.
  • jcr:description - description for the template; appears in the dialog when creating a page.

This node contains a jcr:content (cq:PageContent) node which is used as the basis for the content node of resulting pages; this references, using sling:resourceType, the component to be used for rendering the actual content of a new page.

screen_shot_2012-02-13at64010pm

This component is used to define the structure and design of the content when a new page is created.

screen_shot_2012-02-13at64137pm

The content produced by a Template

Templates are used to create pages of type cq:Page (as mentioned earlier, a page is a special type of component). Each AEM Page has a structured node jcr:content. This:

  • is of type cq:PageContent
  • is a structured node-type holding a defined content-definition
  • has a property sling:resourceType to reference the component holding the sling scripts used for rendering the content

Default Templates

AEM comes with various default templates available out of the box. Sometimes, you may want to use the templates as is. In that case, you must ensure that the template is available for your web site.

For example, AEM comes with several templates including a contentpage and home page.

TitleComponentLocationPurpose
Home PagehomepagegeometrixxThe Geometrixx home page template.
Content PagecontentpagegeometrixxThe Geometrixx content page template.

Displaying Default Templates

To see a list of all templates in the repository, proceed as follows:

  1. In CRXDE Lite, open the Tools menu and click Query.

  2. In the Query tab

  3. As Type, select XPath.

  4. In the Query input field, enter following string:
    //element(*, cq:Template)

  5. Click Execute. The list is displayed in the result box.

Usually, you take an existing template and develop a new one for your own use. See Developing Page Templates for more information.

To enable an existing template for your website and you want it to be displayed in the Create Page dialog when creating a page right under Websites from the Websites console, set the allowedPaths property of the template node to: /content(https://experienceleague.adobe.com/.&?lang=en#42;)?

How Template Designs are Applied

When styles are defined in the UI using Design Mode, the design is persisted at the exact path of the content node for which the style is being defined.

CAUTION
Adobe recommends only applying designs through Design Mode.
Modifying designs in CRXDE Lite, for example, is not best practice and the application of such designs can vary from expected behavior.

If designs are only applied using Design Mode, then the following sections, Design Path Resolution, Decision Tree, and the Example are not applicable.

Design Path Resolution

When rendering content based on a static template, AEM attempts to apply the most relevant design and styles to the content based on a traversal of the content hierarchy.

AEM determines the most relevant style for a content node in the following order:

  • If there is a design for the full and exact path of the content node (as when the design is defined in Design Mode), then use that design.
  • If there is a design for the content node of the parent, then use that design.
  • If there is a design for any node on the path of the content node, then use that design.

In the last two cases, if there is more than one applicable design, use the one closest to the content node.

Decision Tree

This is a graphical representation of the Design Path Resolution logic.

design_path_resolution

Example

Consider a simple content structure as follows, where a design could apply to any of the nodes:

/root/branch/leaf

The following table describes how AEM chooses a design.

Finding Design ForDesigns Exist ForDesign ChosenComment
leaf

root

branch

leaf

leafThe most exact match is always taken.
leaf

root

branch

branchFall back to the closest match lower in the tree.
leafrootrootIf all else fails, take what's remaining.
branchbranchbranch
branch

branch

leaf

branch
branch

root

branch

branch
branch

root

leaf

root

If there is not an exact match, take the one lower in the tree.

The assumption is that this will always be applicable, but further up the tree can be too specific.

Developing Page Templates

AEM page templates are simply models used to create pages. They can contain as little, or as much, initial content as needed, their role being to create the correct initial node structures, with the required properties (primarily sling:resourceType) set to allow editing and rendering.

Creating a Template (based on an existing template)

A new template can be created completely from scratch, but often an existing template is copied instead, and updated to save you time and effort. For example, the templates within Geometrixx can be used to get you started.

To create a template based on an existing template:

  1. Copy an existing template (preferably with a definition as close as possible to what you want to achieve) to a new node.

    Templates are stored in /apps/<website-name>/templates/<template-name>.

    NOTE
    The list of available templates depends on the location of the new page and the restrictions on placement specified in each template. See Template Availability.
  2. Change the jcr:title of the new template node to reflect its new role. You can also update the jcr:description if appropriate. Be sure to change the template availability of the page as appropriate.

    NOTE
    If you want your template to be displayed in the Create Page dialog when creating a page right under Websites from the Websites console, set the allowedPaths property of the template node to: /content(/.*)?

    chlimage_1-88

  3. Copy the component on which the template is based (this is indicated by the sling:resourceType property of the jcr:content node within the template) to create an instance.

    Components are stored in /apps/<website-name>/components/<component-name>.

  4. Update the jcr:title and jcr:description of the new component.

  5. Replace the thumbnail.png if you want a new thumbnail picture to be shown in the template selection list (size 128 x 98 px).

  6. Update the sling:resourceType of the template’s jcr:content node to reference the new component.

  7. Make additional changes to the functionality or design of the template, or its underlying component, or both.

    NOTE
    Changes made to the /apps/<website>/templates/<template-name> node affect the template instance (as in the selection list).
    Changes made to the /apps/<website>/components/<component-name> node affect the content page created when the template is used.

    You can now create a page within your website using the new template.

NOTE
The editor client library assumes the presence of the cq.shared namespace in content pages, and if it is absent, the JavaScript error Uncaught TypeError: Cannot read property 'shared' of undefined results.
All sample content pages contain cq.shared, so any content based on them automatically includes cq.shared. However, if you decide to create your own content pages from scratch without basing them on sample content, you must make sure to include the cq.shared namespace.
See Using Client-Side Libraries for further information.

Making an Existing Template Available

This example illustrates how to allow a template to be used for certain content paths. The templates that are available to the page author when creating pages are determined by the logic defined in Template Availability.

  1. In CRXDE Lite, navigate to the template you want to use for your page, for example, the Newsletter template.

  2. Change the allowedPaths property and other properties used for template availability. For example, allowedPaths: /content/geometrixx-outdoors/[^/]+(/.*)? means that this template is allowed in any path under /content/geometrixx-outdoors.

    chlimage_1-89

Experience Manager


Rapid Feature Releases with AEM Cloud: Telegraph Media Group’s RDE Strategy

Online | Session | Intermediate

Hear how Telegraph Media Group, the award-winning publisher of The Daily Telegraph, The Sunday Telegraph, The Telegraph Magazine,...

Wed, Mar 19, 3:30 PM PDT (10:30 PM UTC)

Register

The True Cost of a Failed Implementation

Online | Session | General Audience

A failed implementation isn’t just an inconvenience — it costs real revenue. Poor execution and misaligned tools disrupt pipelines,...

Wed, Mar 19, 2:00 PM PDT (9:00 PM UTC)

Register

Connect with Experience League at Summit!

Get front-row access to top sessions, hands-on activities, and networking—wherever you are!

Learn more