Vaatate praegu abisisu järgmise versiooni jaoks::
- 6.4
- 6.3
- 6.2
- Vanemad versioonid
A Template is used to create a Page and defines which components can be used within the selected scope. A template is a hierarchy of nodes that has the same structure as the page to be created, but without any actual content.
- Templates are built up of Components;
- Components use, and allow access to, Widgets and these are used to render the Content.
Märkus.
Editable templates are also available.
Name |
Type |
Description |
. |
cq:Template | Current template. A template is of node type cq:Template. |
allowedChildren | String[] | Path of a template that is allowed to be a child of this template. |
allowedParents | String[] | Path of a template that is allowed to be a parent of this template. |
allowedPaths | String[] | Path of a page that is allowed to be based on this template. |
jcr:created | Date | Date of creation of the template. |
jcr:description | String | Description of the template. |
jcr:title | String | Title of the template. |
ranking | Long | Rank of the template. Used to display the template in the User Interface. |
jcr:content | cq:PageContent | Node containing the content of the template. |
thumbnail.png | nt:file | Thumbnail of the template. |
icon.png | nt:file | Icon of the template. |
A template is the basis of a page.
To create a page, the template must be copied (node-tree /apps/<myapp>/template/<mytemplate>) to the corresponding position in the site-tree: this is what happens if a page is created using the Websites tab.
This copy action also gives the page its initial content (usually Top-Level Content only) and the property sling:resourceType, the path to the page component that is used to render the page (everything in the child node jcr:content).

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 be 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.

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

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
AEM comes with a number of default templates available out of the box. In some cases, you may want to use the templates as is. In that case, you need to ensure that the template is available for your web site.
Title | Component | Location | Purpose |
Home Page | homepage | geometrixx | The Geometrixx home page template. |
Content Page | contentpage | geometrixx | The Geometrixx content page template. |
To see a list of all templates in the repository, proceed as follows:
- In CRXDE Lite, open the Tools menu and click Query.
- In the Query tab
- As Type, select XPath.
- In the Query input field, enter following string:
//element(*, cq:Template) - Click Execute. The list is displayed in the result box.
In most cases, you will 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(/.*)?
AEM page templates are simply models used to create new 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.
Needless to say a new template can be created completely from scratch, but often an existing template will be copied and updated to save you time and effort. For example, the templates within Geometrixx can be used to get you started.
To create a new template based on an existing template:
-
Copy an existing template (preferably with a definition as close as possible to what you want to achieve) to a new node.
Märkus.
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.
-
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.
Märkus.
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(/.*)?
-
Make any further changes to the functionality or design of the template and/or its underlying component.
Märkus.
Changes made to the /apps/<website>/templates/<template-name> node will affect the template instance (as in the selection list).
Changes made to the /apps/<website>/components/<component-name> node will affect the content page created when the template is used.
Märkus.
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.
See Using Client-Side Libraries for further information.
When creating a new 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 allowed to be 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:allowedTemplates property of the jcr:content subnode of P or an ancestor of P.
- The allowedPaths property of T.
- The allowedParents property of T.
- The allowedChildren property of the template of P.
The evaluation works as follows:
- The first non-empty cq:allowedTemplates property found while ascending the page hierarchy starting with P is matched against the path of T. If none of the values match, T is rejected.
- If T has a non-empty allowedPaths property, but none of the values match the path of P, T is rejected.
- If both of the above properties are either empty or non-existent, T is rejected unless it belongs to the same application as P. T belongs to the same application as P if and only if the name of the second level of the path of T is the same as the name of the second level of the path of P. For example, the template /apps/geometrixx/templates/foo belongs to the same application as the page /content/geometrixx.
- If T has an non-empty allowedParents property, but none of the values match the path of P, T is rejected.
- If the template of P has a non-empty allowedChildren property, but none of the values match the path of T, T is rejected.
- In all other cases, T is allowed.
The following diagram depicts the template evaluation process:

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.
To make a template available, you need to follow the guidelines (see Template Availability). This example also assumes that you have created the template.
-
Change the allowedPaths property and other properties used for template availabillity. For example, allowedPaths: /content/geometrixx-outdoors/[^/]+(/.*)? means that this template is allowed in any path under /content/geometrixx-outdoors.