Class ThymeleafModule

java.lang.Object
io.jooby.thymeleaf.ThymeleafModule
All Implemented Interfaces:
Extension

public class ThymeleafModule extends Object implements Extension
Thymeleaf module: https://jooby.io/modules/thymeleaf.

Usage:


 {

   install(new ThymeleafModule());

   get("/", ctx -> {
     User user = ...;
     return new ModelAndView("index.html")
         .put("user", user);
   });
 }
 
The template engine looks for a file-system directory: views in the current user directory. If the directory doesn't exist, it looks for the same directory in the project classpath.

Template engine supports the following file extensions: .thl, .thl.html and .html.

You can specify a different template location:


 {

    install(new ThymeleafModule("mypath"));

 }
 
The mypath location works in the same way: file-system or fallback to classpath.

Direct access to TemplateEngine is available via require call:


 {

   TemplateEngine engine = require(TemplateEngine.class);

 }
 
Complete documentation is available at: https://jooby.io/modules/thymeleaf.
Since:
2.0.0
Author:
edgar
  • Constructor Details

    • ThymeleafModule

      public ThymeleafModule(@NonNull org.thymeleaf.TemplateEngine templateEngine)
      Creates a new module uses the given template engine. You can create a default engine using the create() method.
      Parameters:
      templateEngine - Template engine.
    • ThymeleafModule

      public ThymeleafModule(@NonNull String templatesPath)
      Creates module which look at the given path. It first look at the file-system or fallback to classpath.
      Parameters:
      templatesPath - Template path.
    • ThymeleafModule

      public ThymeleafModule(@NonNull Path templatesPath)
      Creates module which look at the given path.
      Parameters:
      templatesPath - Template path.
    • ThymeleafModule

      public ThymeleafModule()
      Creates module module using the default template path: views. It first look at the file-system or fallback to classpath.
  • Method Details

    • install

      public void install(@NonNull Jooby application)
      Specified by:
      install in interface Extension
    • create

      @NonNull public static ThymeleafModule.Builder create()
      Creates a new thymeleaf builder.
      Returns:
      A builder.