Templating
Basics
Before attempting to write new STK templates, we suggest that you first become familiar with Magnolia templating. The following guides and resources are available:
- Introduction to templating
- 4.0 Templating Reference
- Diagram showing relation between definition, model & renderers
- Tag-library Reference
STK Templating
In-place Template Scripts
All of the FreeMarker STK template scripts are accessible in the Templating Kit - Templates workspace. The templates can be immediately changed in Magnolia itself, which is ideal for evaluation, prototyping or smaller projects.

Templates can be edited in the Edit Dialog.

Once a template has been modified, it is necessary to check the Enable template box in order to tell the STK to use the customized template.
Loading Template Scripts
The template scripts can be loaded in three ways. The system searches for a template in the following order and places:
- The filesystem of the webapp;
- The in-place Templates workspace. The template needs to be enabled to be considered; and
- The class path. This is where the default STK templates are located.
- Webapp is ideal when you want to edit real files, but are not going as far as creating a java project;
- In-place Template workspace is suitable for prototyping, if you are using Magnolia as a service or in a wiki-style system;
- Class path is ideal if you use a module, which is recommended for bigger projects or to facilitate team collaboration, as any modifications in your IDE are then immediately loaded.
main.ftl
This is the default entry point for all templates and is configured in the template prototype of the site definition. It is also a very good starting point from which to explore the system.
The following is an abbreviated version of the main.ftl template script.
<!DOCTYPE html PUBLIC "-W3CDTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> [#assign cms=JspTaglibs["cms-taglib"]] [#assign cmsu=JspTaglibs["cms-util-taglib"]]<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="${model.language}" lang="${model.language}">
<head> [#include def.htmlHeader.template] </head>
...
<body ${bodyID} ${bodyClass}> [#if def.dialog?has_content] [@cms.mainBar label="Page Info" dialog="${def.dialog!}" /] [#else] [@cms.mainBar label="" /] [/#if]
<div id="wrapper">
[#include def.header.template]
<div id="wrapper-2"> [#include def.navigation.vertical.template] <div id="wrapper-3"> … <div id="main"> [#if def.breadcrumb.enabled] [#include def.breadcrumb.template] [/#if]
[#include def.mainArea.template]
</div><!-- end main --> … </div><!-- end wrapper-3 --> … </div><!-- end wrapper-2 -->
[#include def.footer.template] </div><!-- end wrapper -->
</body> </html>
<!DOCTYPE html PUBLIC "-W3CDTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> [#assign cms=JspTaglibs["cms-taglib"]] [#assign cmsu=JspTaglibs["cms-util-taglib"]]<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="${model.language}" lang="${model.language}">
<head>
[#include def.htmlHeader.template]
</head>
- create a custom header template, for example /myproject/templates/global/htmlHeader.ftl;
- include the original header template -
[#include "/templating-kit/templates/global/htmlHeader.ftl"]; - add the additional content. Perhaps some special meta tags, inline javascript, etc.
<body ${bodyID} ${bodyClass}>
- vertical navigation shown?, which can change based on the page's level;
- floating teasers;
- extras (enabled, columns, small or big).
[#if def.dialog?has_content]
[@cms.mainBar label="Page Info" dialog="${def.dialog!}" /]
[#else]
[@cms.mainBar label="" /]
[/#if]
[#if def.breadcrumb.enabled]
[#include def.breadcrumb.template]
[/#if]
STK-specific Context Objects
In addition to the normal context objects (being content, def etc.), you can also add a STK object. Some of the common objects are enhanced by additional features.
| Object | Note |
|---|---|
| stk | An instance of the STKUtil |
| content | Same as normal, but will print the content HTML encoded by default. To avoid this, use the following code: ${stk.decode(content).title} |
| def | In the case of a template definition, it is most likely an instance of STKTemplate |
| model | Depends on the modelClass defined in the template, but is most likely an instance of an STKTemplateModel |
The following are some useful snippets:
the current site definition: ${model.site.name}
the current site root: ${model.siteRoot.title}
Resources (Javascripts and CSS)

Configuration
CSS and javascript files can be defined on three levels:
- theme;
- site definition; and
- template definition.
Bypassing the Workspace
The content in the workspace can be bypassed by checking the "bypass" option in the advanced tab. In that case the corresponding file in the class path will be used. This is mainly useful while developing or testing.

FreeMarker based resources
If a resource is of the type "processed", the content is interpreted as a FreeMarker template. This facilitates the use of constants, variables or any other logic. In the dialog of processed resources, it is possible to define the model class to be used, so that you can use any java logic or Magnolia functionality.

Aggregation of Javascripts
The /templating-kit/js/all script is an aggregation script, which combines all child pages into a single file. It also sets a context path variable that is used by some of the scripts.
/** * Aggregated script. All javascripts under this node will be included. */var contextPath = '${contextPath}';
[#list content?children as subnode] ${mgnl.renderTemplate(subnode)} [/#list]