This tutorial shows the steps necessary to enable in-place templating in a Blossom project. In-place templating allows you to edit your templates in AdminCentral. It can be very useful when you need to update a template in a live production environment.
Note that this is not possible for JSP templates.
Add the dependency to your module
Add this to your pom.xml:
And this to your module descriptor (/src/main/resources/META-INF/magnolia/myModule.xml):
This is necessary to ensure that the in-place templating module is started before your module. For more details see the documentation of the module mechanism.
Make sure your templates are on the classpath
The general convention is to keep your freemarker templates on the classpath in a package with the same name as your module.
The ViewResolvers for this module would look like this:
In this setup a paragraph that uses the myparagraph.ftl template will simple return myparagraph and the ViewResolver will know where it is thanks to the configured prefix and suffix.
Install the templates
When your module is installed it needs to install its templates into the templating repository. This is done by adding a task in your VersionHandler.
And that's it!
In AdminCentral you now have a new menu option called Templating. It displays all the installed templates and you can edit them as you like. Don't forget to enable the template otherwise the original from the classpath will still be used.
A note on mixing freemarker and JSP templates
When you use both freemarker and JSP's in your project you need to configure a view resolver for each type and return view names from your controllers that clearly maps to only one of them. A common way of doing this is to return viewNames with the extension, and then specify a pattern on the ViewResolver that matches the extension.
The ViewResolver in this example will only be used when the controller returns a view name that ends with .ftl.