Pages & templates - bartoszWesolowski/aem-tips GitHub Wiki

Pages and Templates

Editable Templates

  • Tools > General > Templates
  • editable templates and policies are stored unde /conf
  • at root of each site (for example /content/wknd) you can set a cq:allowedTemplates property (available in page properties) to fix which templates should be used for particular page
  • uses content policies to persist design properties
  • changes on template will reflect changes on pages created with that template
  • maintained by template-authors group Main areas:
  • Structure - defines components that are a part of the template. These will not be editable by content authors. Components in this mode might be locked (they can be edited on template only) or unlocked (can be edited on page based on template)
  • Initial Content - defines components that the template will start with, these can be edited and/or deleted by content authors
  • Policies - defines configurations on how components will behave and what options authors will have available. Policies can be reused in multiple places which minimize configuration duplication.

Enabling template

By default new templates will be in a draft state - this means that author can not use this template yet. After template it's configured it has to be enabled to make it available for authors. To do that open templates view select template do enable, click on ... button and then enable.

Author can configure which templates can be used in different content branches. This can be set in page properties (advance tab). For example to use all templates available for the project the following value can be set:

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

If this is not set on a page level this value will be searched in the parent pages (first found will be applied)

Template type

  • Created by developers - has to be created with AEM interface and some of the properties needs to be added manually (either in crx or in directly on source control)
  • OOTB templates types available under /libs/settings/wcm/template-types

Creating template types for new project

  • To create new template types (and in general configuration for new project) go to Tools -> General -> Configuration Browser and create new configuration directory with templates enabled
  • Create new directory for your new template type: simple-page
  • Manually add the following properties to template files:
\template-types
   \custom-template-type (cq:Template)
      \jcr:content (cq:PageContent)
        - jcr:title: Simple page
        - jcr:description Example template type
       \initial (cq:Page)
          \jcr:content (cq:PageContent) 
              - sling:resourceType -> resource/type/to/project/page/renderer
       \structure (cq:Page)
           \jcr:content (cq:PageContent)  
              - sling:resourceType -> resource/type/to/project/page/renderer
       \policies (cq:Page)
           \jcr:content (nt:unstructured) 
               - sling:resourceType -> wcm/core/components/policies/mappings
               \root (nt:unstructured) 
                   - sling:resourceType -> wcm/core/components/policies/mapping

Policies

Component policy on template

Policy are similar to configurations. The advantage of component policy is that we can reuse policy on components that are placed on templates. To open component policy hit the edit policy button policy

Layout container policy

Policy of a layout container contains a configuration that controls which components can be added to this layout (similar mechanism as design configuration in static templates).

Static templates

  • created and configured by developers, under /apps/
  • use design mode to persist design properties
  • changes to template structure will not reflect page already created based on it
  • cq:Template node

Making template available in content structure is managed by the following properties:

  • allowedChildren - Path of a template that is allowed to be a child of this template.
  • allowedParents - Path of a template that is allowed to be a parent of this template.
  • allowedPaths - Path of a page that is allowed to be based on this template

Documentation