Search in sources :

Example 1 with ThymeleafTemplateEngine

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);
}
Also used : ThymeleafTemplateEngine(io.vertx.ext.web.templ.thymeleaf.ThymeleafTemplateEngine) Router(io.vertx.ext.web.Router) JsonObject(io.vertx.core.json.JsonObject)

Example 2 with ThymeleafTemplateEngine

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());
}
Also used : ThymeleafTemplateEngine(io.vertx.ext.web.templ.thymeleaf.ThymeleafTemplateEngine) Test(org.junit.Test)

Aggregations

ThymeleafTemplateEngine (io.vertx.ext.web.templ.thymeleaf.ThymeleafTemplateEngine)2 JsonObject (io.vertx.core.json.JsonObject)1 Router (io.vertx.ext.web.Router)1 Test (org.junit.Test)1