public class Thl extends Object implements Jooby.Module
Thymeleaf is a modern server-side Java template engine for both web and standalone environments.
TemplateEngineView.Engine
{
use(new Thl());
get("/", () -> {
return Results.html("index")
.put("model", new MyModel());
});
// Or Thymeleaf API:
get("/thymeleaf-api", () -> {
TemplateEngine engine = require(TemplateEngine.class);
engine.processs("template", ...);
});
}
Templates are loaded from root of classpath: / and must end with: .html
file extension. Example:
public/index.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<body>
<p>
Hello <span th:text="${model.name}">World</span>!!!
</p>
</body>
</html>
Templates are loaded from the root of classpath and must end with
.html. You can change the default template location and/or extensions:
{
use(new Thl("templates", ".thl"));
}
A template engine has access to request locals (a.k.a attributes). Here is an example:
{
use(new Thl());
get("*", req -> {
req.set("foo", bar);
});
}
Then from template:
<span th:text="${who}">World</span>
Cache is OFF when env=dev (useful for template reloading), otherwise is ON.
Advanced configuration if provided by callback:
{
use(new Thl().doWith(engine -> {
engine.addDialect(...);
}));
}
| Constructor and Description |
|---|
Thl()
Creates a new thymeleaf module.
|
Thl(String prefix,
String suffix)
Creates a new thymeleaf module.
|
| Modifier and Type | Method and Description |
|---|---|
void |
configure(Env env,
com.typesafe.config.Config conf,
com.google.inject.Binder binder) |
Thl |
doWith(BiConsumer<org.thymeleaf.TemplateEngine,com.typesafe.config.Config> callback)
Set a configuration callback.
|
Thl |
doWith(Consumer<org.thymeleaf.TemplateEngine> callback)
Set a configuration callback.
|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitconfigpublic Thl(String prefix, String suffix)
prefix - Template prefix.suffix - Template suffix.public Thl()
public Thl doWith(Consumer<org.thymeleaf.TemplateEngine> callback)
{
use(new Thl().doWith(engine -> {
...
}));
}
callback - Callback.public Thl doWith(BiConsumer<org.thymeleaf.TemplateEngine,com.typesafe.config.Config> callback)
{
use(new Thl().doWith(engine -> {
...
}));
}
callback - Callback.public void configure(Env env, com.typesafe.config.Config conf, com.google.inject.Binder binder) throws Throwable
configure in interface Jooby.ModuleThrowableCopyright © 2017. All rights reserved.