1. Freemarker
Freemarker templates for Jooby.
1.1. Usage
1) Add the dependency:
<dependency>
<groupId>io.jooby</groupId>
<artifactId>jooby-freemarker</artifactId>
<version>3.5.3</version>
</dependency>
2) Write your templates inside the views
folder
<p> Hello ${name}! </p>
3) Install and use freemarker templates
import io.jooby.freemarker.FreemarkerModule;
{
install(new FreemarkerModule());
get("/", ctx -> {
return new ModelAndView("index.ftl")
.put("name", "Jooby");
});
}
Template engine supports the following file extensions: .ftl
, .ftl.html
and .html
.
1.2. Templates Location
Template location is set to views
. The views
folder/location is expected to be at the current
user directory or at root of classpath.
You can override the default location by setting the templates.path
property in the application
configuration file or programmatically at creation time.
1.3. Template Cache
The freemarker module turn off cache while running in dev
or test
environment. For any other
environment it use a soft cache.
To set a different template cache just set the freemarker.cacheStorage
property.
1.4. Freemarker Configuration
Freemarker options can be set from application configuration properties by using the freemarker
prefix:
freemarker.cacheStorage = soft
freemarker.strictSyntax = yes
Custom Configuration object can be provided it programmatically:
import io.jooby.freemarker.FreemarkerModule;
{
Configuration freemarker = new Configuration();
install(new FreemarkerModule(freemarker));
}