public class Ftl extends Object implements Jooby.Module
Configuration and a Renderer.
It is pretty straightforward:
{
use(new Ftl());
get("/", req -> Results.html("index").put("model", new MyModel());
}
public/index.html:
${model}
Templates are loaded from root of classpath: / and must end with: .html
file extension.
There are two ways of changing a Freemarker configuration:
Just add a freemarker.* option to your application.conf file:
freemarker.default_encoding = UTF-8
{
use(new Ftl().doWith((freemarker, config) -> {
freemarker.setDefaultEncoding("UTF-8");
});
}
Keep in mind this is just an example and you don't need to set the default encoding. Default
encoding is set to: application.charset which is UTF-8 by default.
Templates are loaded from the root of classpath and must end with .html. You can
change the default template location and extensions too:
{
use(new Ftl("/", ".ftl"));
}
Cache is OFF when env=dev (useful for template reloading), otherwise is ON.
Cache is backed by Guava and default cache will expire after 100 entries.
If 100 entries is not enough or you need a more advanced cache setting, just set the
freemarker.cache option:
freemarker.cache = "expireAfterWrite=1h"
See CacheBuilderSpec.
That's all folks! Enjoy it!!!
| Constructor and Description |
|---|
Ftl() |
Ftl(String prefix) |
Ftl(String prefix,
String suffix) |
| Modifier and Type | Method and Description |
|---|---|
com.typesafe.config.Config |
config() |
void |
configure(Env env,
com.typesafe.config.Config config,
com.google.inject.Binder binder) |
Ftl |
doWith(BiConsumer<freemarker.template.Configuration,com.typesafe.config.Config> configurer) |
public Ftl(String prefix)
public Ftl()
public Ftl doWith(BiConsumer<freemarker.template.Configuration,com.typesafe.config.Config> configurer)
public void configure(Env env, com.typesafe.config.Config config, com.google.inject.Binder binder)
configure in interface Jooby.Modulepublic com.typesafe.config.Config config()
config in interface Jooby.ModuleCopyright © 2015. All rights reserved.