Template scripts
A template script defines the output (typically HTML) and is interpreted by Renderer
.
The script is written in a templating language such as FreeMarker.
In the context of developing single-page applications, the elements comparable to FreeMarker template scripts are components. These are compiled into a single HTML page. On the Magnolia side, page rendering is handled by the SPA renderer.
A template script is a mixture of:
-
Static markup
-
Dynamically assigned values provided by
TemplatingFunctions
and other convenience helpers -
Content references
FreeMarker
At Magnolia, we prefer FreeMarker for its flexibility, clean syntax and practical error reporting.
Magnolia 6.2.52 includes FreeMarker version 2.3.32.
You can use the .version
special variable in a template to check this.
If you are not familiar with FreeMarker, these links will get you started:
-
FreeMarker built-ins are the
?
bits that follow expressions and provide useful functionality.
The Magnolia CLI offers the |
Automatically escape .html in Freemarker
Freemarker recommends that you configure Freemarker so that templates with ftlh
extensions are automatically associated with .html
files.
By default, Magnolia’s pattern does not look for .ftlh
extensions.
In order to automatically escape .html
files, you need to add the .ftlh
extension to the magnolia.resources.classpath.observation.pattern
property.
# Pattern to define which resources should be observed by ClasspathScanner
magnolia.resources.classpath.observation.pattern=.*\\.(ftl|ftlh|yaml)$ (1)
1 | In this case, ftl , ftlh , and yaml files are observed. |