Magnolia 5.3 reached end of life on June 30, 2017. This branch is no longer supported, see End-of-life policy.
Magnolia loads template scripts from the following locations in this order. As soon as it finds a script, it stops looking.
/mgnl-files/templates
in your module Magnolia deploys them to /<CATALINA_HOME>/webapps/<contextPath>/templates/
on the file system.templates
workspace. The script needs to be enabled (box checked) to be considered for loading. You can load only Freemarker scripts from the repository.The FreeMarker renderer can load template "files" through any object that implements the freemarker.cache.TemplateLoader
interface. The templates need not be real files and can come from any kind of data source such as classpath, servlet context or database.
Magnolia provides three FreeMarker template loader implementations:
JcrRepoTemplateLoader
loads templates from the repository. By default it loads templates from the templates
workspace but you can configure another workspace. This loader is included in the In-place Templating module. LazyFileTemplateLoader
loads templates from an arbitrary location on the file system.FreeMarker template loaders are configured in /server/rendering/freemarker/templateLoaders
.
Node name | Value |
---|---|
server | |
rendering | |
freemarker | |
templateLoaders | |
jcr | |
class | info.magnolia.module.inplacetemplating.JcrRepoTemplateLoader |
extension | .ftl |
workspace | templates |
webapp | |
class | info.magnolia.freemarker.loaders.LazyWebappTemplateLoader |
You can also write your own custom template loader if needed.
Editing template scripts in the repository is not maintainable in the long run because the changes don't make their way into the module. You can use this approach for evaluation and prototyping but don't do it in a production environment. We strongly recommend that you store the scripts in a version control system and package them into a project module.
In order to edit template scripts in the repository, install them into the templates
workspace. This is useful for prototyping or developing but it only works with FreeMarker scripts. The scripts become editable in the Templates app.
Add a TemplatesInstallTask
into your module version handler. Here is an example from the Standard Templating Kit module ( Git ):
import info.magnolia.module.inplacetemplating.setup.TemplatesInstallTask; // Install scripts when the module is installed for the first time. @Override protected List<Task> getExtraInstallTasks(InstallContext ctx) { final List<Task> tasks = new ArrayList<Task>(); tasks.addAll(super.getExtraInstallTasks(ctx)); tasks.add(new TemplatesInstallTask("/templating-kit/.*\\.ftl", true));@Override // Reinstall scripts when the module is updated. @Override protected List<Task> getDefaultUpdateTasks(Version forVersion) { final List<Task> tasks = new ArrayList<Task>(); tasks.addAll(super.getDefaultUpdateTasks(forVersion)); tasks.add(new TemplatesInstallTask("/templating-kit/.*\\.ftl", true)); return tasks; }
To edit a template script in the repository:
main.ftl
script is in a /templating-kit/pages
folder inside the module JAR. Creating the matching folders in the repository allows the repository script override the classpath script.
To install JSP scripts on to the file system put them in /mgnl-files/templates/<module-name>
in your module. Magnolia deploys them to /<CATALINA_HOME>/webapps/<contextPath>/templates/
on the file system during module install and update.