Templates templates
Templates are used at various points in AEM:
-
When you create a page, you select a template. This template is used as the base for the new page. The template defines the structure of the page, any initial content, and the components that can be used (design properties).
-
When you create a Content Fragment, you also select a template. This template defines the structure, initial elements, and variations.
The following templates are covered in detail:
Templates - Pages templates-pages
AEM now offers two basic types of templates for creating pages:
Editable Templates editable-templates
Editable templates are now considered best practices for developing with AEM.
The advantages of Editable Templates:
-
Have been introduced to let you define the following for any pages created with the template:
- the structure
- the initial content
- content policies
-
After the new page is created, a dynamic connection is maintained between the page and the template. This connection means that changes to the template structure are reflected on any pages created with that template; changes to the initial content are not reflected.
-
Uses content policies (edited from the template editor) to persist the design properties (does not use Design mode within the page editor).
-
Are stored under
/conf -
See Editable Templates for further information.
Static Templates static-templates
Static Templates:
- Must be defined and configured by your developers.
- The original templating system of AEM that has been available for many versions.
- A static template is a hierarchy of nodes that has the same structure as the page to be created, but without any actual content.
- Are copied to create the page, no dynamic connection exists afterward.
- Uses Design Mode to persist design properties.
- Are stored under
/apps - See Static Templates for further information.
Template Availability template-availability
-
only the
cq:allowedTemplatesproperty -
only on the site root
/content/we-retail/jcr:contentallowedPaths, allowedParents, and allowedChildren can also be placed on the templates to define more sophisticated rules. However, when possible, it is much simpler to define further cq:allowedTemplates properties on subsections of the site if there is a need to further restrict the allowed templates.cq:allowedTemplates properties can be updated by an author in the Advanced tab of the Page Properties. The other template properties cannot be updated using the (standard) UI, so would need a developer to maintain the rules and a code deployment for every change.When creating a page in the site admin interface, the list of available templates depends on the location of the new page and the restrictions on placement specified in each template.
The following properties determine whether a template T is used for a new page to be placed as a child of page P. Each of these properties is a multi-value string holding zero or more Regular Expressions that are used for matching with paths:
-
The
cq:allowedTemplatesproperty of thejcr:contentsubnode ofPor an ancestor ofP. -
The
allowedPathsproperty ofT. -
The
allowedParentsproperty ofT. -
The
allowedChildrenproperty of the template ofP.
The evaluation works as follows:
-
The first non-empty
cq:allowedTemplatesproperty found while ascending the page hierarchy starting withPis matched against the path ofT. If none of the values match,Tis rejected. -
If
Thas a non-emptyallowedPathsproperty, but none of the values match the path ofP,Tis rejected. -
If both of the above properties are either empty or non-existent,
Tis rejected unless it belongs to the same application asP.Tbelongs to the same application asPif and only if the name of the second level of the path ofTis the same as the name of the second level of the path ofP. For example, the template/apps/geometrixx/templates/foobelongs to the same application as the page/content/geometrixx. -
If
Thas a non-emptyallowedParentsproperty, but none of the values match the path ofP,Tis rejected. -
If the template of
Phas a non-emptyallowedChildrenproperty, but none of the values match the path ofT,Tis rejected. -
In all other cases,
Tis allowed.
The following diagram depicts the template evaluation process:
Limiting templates used in child pages limiting-templates-used-in-child-pages
To limit what templates can be used to create child pages under a given page, use the cq:allowedTemplates property of jcr:content node of the page to specify the list of templates to be allowed as child pages. Each value in the list must be an absolute path to a template for an allowed child page, for example, /apps/geometrixx/templates/contentpage.
You can use the cq:allowedTemplates property on the template’s jcr:content node to have this configuration applied to all newly created pages that use this template.
If you want to add more constraints, for example, regarding the template hierarchy, you can use the allowedParents/allowedChildren properties on the template. You can then explicitly specify that pages created from a template T have to be parents/children of pages created from a template T.
Templates - Content Fragments templates-content-fragments
See Content Fragment Templates.