Knowing how to create custom templates is a fundamental front end skill and one that you need to be very familiar with when working with Magnolia CMS.
Function of a Template Definition
What is a template definition?
A definition just means 'configuration'. The Java interface
is the base interface of every page and component definition. Because the
, the same configurations are possible on areas as on pages and component definitions.
such as Pages and Components are registered within a module's node
Creating a template
What is the minimum required configuration for a template?
To be renderable a TemplateDefinition must have.
templateScriptWhat script to render the output with. The path to the scripts start within the jar module, absolute path after
renderTypeWhat renderer to use, e.g. Freemarker, JSP, stk.
dialogStrictly speaking this is optional - but you will need a dialog to create and edit the content. The dialog is referenced with: module-name:path-to-dialog
As best practice the template definition should have:
titleThe title of the definition the author sees, e.g Article, News
descriptionA description providing information to the author about the page or component.
Additionally important configuration possibilities on a TemplateDefinition are:
modelClassThis enables you to attach a Java model class to the
TemplateDefintion, see RenderingModelImpl.
areasThese define a collection of components to add.
parametersproviding parameters as definition driven constants usable within the scripts and model class.
Not every template defiiniton will feature all of the possible configuration options. Here is a typical STK template definition (stkArticle):
Every template definition is capable of auto generating content. You can enable auto generation of content by configuring an
autoGeneration node within the area definition. An
autoGeneration configuration expects a
generator class defined.
Is there a default generator?
The default generator implementation provided is the CopyGenerator. In turn, the copy generator expects a node
content, in order to create a copy process. The copy generator will copy the sub content of the node
content. The content is copied 1:1 except for two values:
nodeTypeis used as
jcr:primaryTypeon creation of the node
templateIdis used to set the value
metaDataof the created node.
Any kind of auto generator class could be plugged in, for example a '
BootstrapGenerator'. With this auto copy mechanism, a complete page structure with all areas and components could be auto created. STK is primarily used for creating the main component in feature pages.