Skip to content

Latest commit

 

History

History
97 lines (68 loc) · 1.88 KB

handlebars.adoc

File metadata and controls

97 lines (68 loc) · 1.88 KB

Handlebars

Usage

1) Add the dependency:

.

2) Write your templates inside the views folder

views/index.hbs
<p> Hello {{name}}! </p>

3) Install and use freemarker templates

Java
import io.jooby.handlebars.HandlebarsModule;

{
  install(new HandlebarsModule());

  get("/", ctx -> {
    return new ModelAndView("index.hbs")
        .put("name", "Jooby");
  });
}
Kotlin
import io.jooby.handlebars.HandlebarsModule

{
  install(HandlebarsModule())

  get("/") {
    ModelAndView("index.hbs")
        .put("name", "Jooby")
  }
}

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

Templates Location

Template location is set to views. The views folder/location is expected to be at the current user directory or at root of classpath.

You can override the default location by setting the templates.path property in the application configuration file or programmatically at creation time.

Template Cache

The handlebars module turn off cache while running in dev or test environment. For any other environment it use HighConcurrencyTemplateCache

Custom configuration

Custom Handlebars object can be provided it programmatically:

Java
import io.jooby.handlebars.HandlebarsModule;

{
  Handlebars handlebars = new Handlebars();

  // Apply custom configuration

  install(new HandlebarsModule(handlebars));
}
Kotlin
import io.jooby.handlebars.HandlebarsModule

{
  val handlebars = Handlebars()

  // Apply custom configuration

  install(HandlebarsModule(handlebars))
}