use of io.vertx.ext.web.templ.thymeleaf.ThymeleafTemplateEngine in project vertx-examples by vert-x3.
the class Server method start.
@Override
public void start() throws Exception {
// To simplify the development of the web components we use a Router to route all HTTP requests
// to organize our code in a reusable way.
final Router router = Router.router(vertx);
// In order to use a Thymeleaf template we first need to create an engine
final ThymeleafTemplateEngine engine = ThymeleafTemplateEngine.create(vertx);
// Entry point to the application, this will render a custom JADE template.
router.get().handler(ctx -> {
// we define a hardcoded title for our application
JsonObject data = new JsonObject().put("welcome", "Hi there!");
// and now delegate to the engine to render it.
engine.render(data, "templates/index.html", res -> {
if (res.succeeded()) {
ctx.response().end(res.result());
} else {
ctx.fail(res.cause());
}
});
});
// start a HTTP web server on port 8080
vertx.createHttpServer().requestHandler(router).listen(8080);
}
use of io.vertx.ext.web.templ.thymeleaf.ThymeleafTemplateEngine in project vertx-web by vert-x3.
the class ThymeleafTemplateTest method testGetThymeLeafTemplateEngine.
@Test
public void testGetThymeLeafTemplateEngine() {
ThymeleafTemplateEngine engine = ThymeleafTemplateEngine.create(vertx);
assertNotNull(engine.getThymeleafTemplateEngine());
}
Aggregations