Provide templates that retain a dynamic connection to any pages created from them. This ensures that any changes to the template are reflected in the pages themselves.

Make the page component more generic so the core page component can be used without customization.

With editable templates, the pieces that make a page are isolated within components. You can configure the necessary combinations of components in a UI, thereby eliminating the need for a new page component to be developed for each page variation.

This document assumes that you are already familiar with creating and editing templates. See the authoring document Creating Page Templates, which details the capabilities of editable templates as exposed to the template author.

Creating a New Template

Creating editable templates is primarily done with the template console and template editor by a template author. This section gives an overview of this process and follows with a description of what occurs at a technical level.

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 will result.

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.

Template Folders

Site-specific
The site-specific folders that you create to organize your templates are created with an account holding admin priviliges.

Observação:

Even though you can nest your folders, when the user views them in the Templates console they are presented as a flat structure.

In a standard AEM instance the global folder already exists in the template console. This holds default templates and acts as a fallback if no policies and/or template-types are found in the current folder. You can add your default templates to this folder or create a new folder (recommended).

Observação:

It is best practice to create a new folder to hold your customized templates and not to use the global folder.

Cuidado:

Folders must be created by a user with admin rights.

Template types and policies are inherited across all folders according to the following order of precedence:

The current folder.

Parent(s) of the current folder.

/conf/global

/apps

/libs

A list of all allowed entries is created. If any configurations overlap (path/label), only the instance closest to the current folder is presented to the user.

To create a new folder, you can either do this:

Programmatically or with CRXDE Lite

Using the Configuration Browser

Using CRXDE Lite

A new folder (under /conf) can be created for your instance either programmatically or with CRXDE Lite.

Value: The title (for the folder) you want to appear in the Templates console.

In addition to the standard authoring permissions and privileges (e.g. content-authors) you now need to assign group(s) and define the required access rights (ACLs) for your authors to be able to create templates in the new folder.

The template-authors group is the default group that needs to be assigned. See the following section ACLs and Groups for details.

Using the Configuration Browser

The existing folders are listed to the left including the global folder.

Click Create.

In the Create Configuration dialog the following fields need to be configured:

Title: Provide a title for the configuration folder

Editable Templates: Tick to allow for editable templates within this folder

Click Create

Observação:

In the Configuration Browser, you can edit the global folder and activate the Editable Templates option if you wish to create templates within this folder, however this is not recommended best practice.

ACLs and Groups

Once your template folders are created (either via CRXDE or with the Configuration Browser), ACLs must defined for the appropriate groups for the template folders to ensure proper security.

Content authors need to activate the policies of a template of a page when activating a page

/conf/<site>/settings/template-types

Template Author

read

Template author creates a new template based on one of the predefined template types.

Anonymous Web User

none

Anonymous Web User must not access the template types

This default template-authors group only covers the project setups, where all template-authors members are allowed to access and author all templates. For more complex setups, where multiple template authors groups are needed to separate access to templates, more custom template authors groups must be created. However the permissions for the template authors groups would still be the same.

Legacy Templates under /conf/global

Templates should no longer be stored in /conf/global, however for some legacy installations there may still be templates in this location. ONLY in such legacy situations should the following /conf/global paths be explicitly configured.

Content authors need to activate the policies of a template of a page when activating a page

/conf/global/settings/wcm/template-types

Template Author

read

Template author creates a new template based on one of the predefined template types

Anonymous Web User

none

Anonymous Web User must not access the template types

Template Type

When creating a new template you need to specify a template type:

Template types effectively provide templates for a template. When creating a new template the structure and initial content of the selected template type is used to create to the new template.

The template type is copied to create the template.

Once the copy has occurred, the only connection between the template and the template type is a static reference for information purposes.

Template types allow you to define:

The resource type of the page component.

The policy of the root node, which defines the components allowed in the template editor.

It is recommended to define the breakpoints for the responsive grid and setup of the mobile emulator at on the template type. This is optional, because the configuration could also be defined on the individual template (see Template Type and Mobile Device Groups).

AEM provides a small selection of out-of-the-box template types such as HTML5 Page and Adaptive Form Page.

Additional examples are provided as a part of the We.Retail sample content.

Template types are typically defined by developers.

The out-of-the box template types are stored under:

/libs/settings/wcm/template-types

Cuidado:

You must not change anything in the /libs path. This is because the content of /libs is overwritten the next time you upgrade your instance (and may be overwritten when you apply either a hotfix or feature pack).

Your site-specific template types should be stored in the comparable location of:

/apps/settings/wcm/template-types

Definitions for your customized templates types should be stored in user-defined folders (recommended) or alternatively in global. For example:

/conf/<my-folder-01>/<my-folder-02>/settings/wcm/template-types

/conf/<my-folder>/settings/wcm/template-types

/conf/global/settings/wcm/template-types

Cuidado:

The template types have to respect the correct folder structure (i.e. /settings/wcm/...), otherwise the template types will not be found.

Template Type and Mobile Device Groups

The device groups used for an editable template (set as relative path of the property cq:deviceGroups) define which mobile devices are available as emulators in the layout mode of page authoring. This value can be set in two places:

On the editable template type

On the editable template

When creating a new editable template, the value is copied from the template type to the individual template. If the value is not set on the type, it can be set on the template. Once a template is created, there is no inheritance from the type to the template.

Cuidado:

The value of cq:deviceGroups must be set as a relative path such as mobile/groups/responsive and not as an absolute path such as /etc/mobile/groups/responsive.

Observação:

With static templates, the value of cq:deviceGroups could be set at the root of the site.

With editable templates, this value is now stored at the template level and is not supported at the page root level.

Creating Template Types

If you have created a template that can serve as the basis of other templates, you can copy this template as a template type.

Create a template as you would any editable template as documented here, which will serve as the basis of your template type.

Using CRXDE Lite, copy the newly-created template from the templates node to the template-types node under the template folder.

Layout

Content Policies

The content (or design) policies define the design properties of a component. For example, the components available or minimum/maximum dimensions. These are applicable to the template (and pages created with the template). Content policies can be created and selected in the template editor.

The property cq:policy, on the root node/conf/<your-folder>/settings/wcm/templates/<your-template>/policies/jcr:content/root
Provides a relative reference to the content policy for the page's paragraph system.

The property cq:policy, on the component-explicit nodes under root, provide links to the policies for the individual components.

Set the property: cq:allowedTemplates
On the jcr:content node of the required branch.

For example, with a value of:

/conf/<your-folder>/settings/wcm/templates/.*

Resultant Content Pages

Pages created from editable templates:

Are created with a subtree that is merged from structure and initial in the template

Have references to information held in the template and template type. This is achieved with a jcr:content node with the properties:

cq:template
Provides the dynamic reference to the actual template; enables changes to the template to be reflected on the actual pages.

cq:templateType
Provides a reference to the template type.

The above diagram shows how templates, content, and components interrelate:

Controller - /content/<my-site>/<my-page>
The resultant page that references the template. The content controls the entire process. According to the definitions it accesses the appropriate template and components.

View - /apps/<my-site>/components
On both the author and publish environments the content is rendered by components.

When rendering a page:

Templates:

The cq:template property of its jcr:content node will be referenced to access the template that corresponds to that page.

Components:

The page component will merge the structure/jcr:content tree of the template with the jcr:content tree of the page.

The page component will only allow the author to edit the nodes of the template structure that have been flagged as editable (as well as any children).

When rendering a component on a page, the relative path of that component will be taken from the jcr:content node; the same path under the policies/jcr:content node of the template will then be searched.

The cq:policy property of this node points to the actual content policy (i.e. it holds the design configuration for that component).

This allows you to have multiple templates that re-use the same content policy configurations.