Magnolia 5.4 reached end of life on November 15, 2018. This branch is no longer supported, see End-of-life policy.

Page tree
Skip to end of metadata
Go to start of metadata

A template definition gives a template a name and makes it available to the system. At a minimum a template definition must specify a script and a rendererYou can configure a template in a YAML file or a JCR node.

Template definition types

Magnolia has three types of template definitions:

Common template properties

Simple template definition:

renderType: freemarker 
templateScript: /my-module/templates/pages/home.ftl
dialog: my-module:pages/homePageProperties
class: com.example.templates.CustomTemplateDefinition
modelClass: com.example.templates.HomePageModel
Node nameValue












You can use common template properties in pagearea and component definitions. Each template type has its own specific properties too.



Renderer to use. Magnolia supports freemarker and jsp renderers by default.

If you have the Site module you can set renderType=site, then define a common templateScript in the template prototype to use on all pages of the site.

You can also create a custom renderer.



Path to the template script as /<module>/templates/<type>/<file>.<ext> format. See Resources for more about script storage locations.



Dialog definition ID in <module-name>:<path to dialog definition> format.

The ID has two parts, separated by a colon:

  1. <module-name> : The name of the module which contains the dialog definition.
  2. <path>: Relative path to the dialog definition inside dialogs root item. For example the dialog ID my-module:pages/homePageProperties either points to the YAML file $magnolia.home/my-module/dialogs/homePageProperties.yaml or to the JCR node /modules/my-module/dialogs/homePageProperties in the configuration workspace.




Title of the template displayed to editors. The value can be literal or retrieved from a message bundle (which is defined in i18nBasename) with a key. Use alphanumeric characters in literal values.

Displayed in:

  • Pages: Template dropdown in the Pages app.
  • Areas: Area toolbar in the page editor.
  • Components: Component toolbar in the page editor.


Template description displayed to editors. The value can be literal or retrieved from the message bundle (specified by i18nBasename) with a key.



The fully-qualified class name for the Java bean representing the definition data of this item. The default class is TemplateDefinition .

Only set the value when using custom definition class. Example: com.example.templates.CustomTemplateDefinition.



A model class that contains business logic for the template. The model class needs to implement the RenderingModel interface. The renderer creates a bean based on the modelClass. Current content, definition and the parent model are passed to the constructor. This object is instantiated for each rendering of a page or component.

(warning) Magnolia 5.4.5+ A Groovy model class can be referenced from a YAML template definition. 

Current limitations:

  • A Groovy model cannot be supplied as a file, you can only reference a Groovy model stored in JCR. (See the Groovy module.)
  • The reference path cannot include the hyphen character.


  • Java models: Fully-qualified class name. Example: com.example.templates.HomePageModel.
  • Groovy models: Path to the model using dot notation such as myModule.templates.components.LinkModel.


Custom template properties that you can access from a script without having to write a class.


optional, in JCR node configuration only 



Custom template properties

Use a parameters item in any template definition to add custom properties without having to write a custom class. Access the properties from your script using the def.parameters.<parameter-name> notation. See def.

  example: my-value
Node nameValue

 <template name>




To access the example parameter in a Freemarker script, use:


Reusing configuration

Magnolia provides mechanisms to reuse configuration items such as template definitions or dialogs. Read Reusing configuration and Extend JCR node based template definition for further information.