Spring Boot Starter support for Handlebars.java (logic-less templates).
Add handlebars-spring-boot-starter
as dependency:
repositories {
mavenCentral()
}
dependencies {
compile 'pl.allegro.tech.boot:handlebars-spring-boot-starter:$version'
}
Since version 0.5.0 handlebars-spring-boot-starter requires Spring Boot 3, Spring Framework 6 and Java 17.
Spring Boot Starter Handlebars will automatically register handlebars helpers based on project dependencies. Add any handlebars helper to dependencies and you can start using it.
dependencies {
compile 'com.github.jknack:handlebars-helpers:4.4.0',
'com.github.jknack:handlebars-jackson:4.4.0'
}
NOTE: JacksonHelper will register with name json
.
Every other helper will register with its default name.
More information about available helpers can be found on Handlebars.java.
To register a custom helper use @HandlebarsHelper annotation.
@HandlebarsHelper
public class CustomHelper {
CharSequence foo() {
return 'bar'
}
}
More information about how to create custom helpers can be found on Using a HelperSource
Properties space is: handlebars
. All basic properties of
AbstractTemplateViewResolverProperties.java
are available.
Default configuration:
handlebars.enabled: true
handlebars.prefix: classpath:templates/
handlebars.suffix: .hbs
handlebars.cache: true
handlebars.registerMessageHelper: true
handlebars.failOnMissingFile: false
handlebars.bindI18nToMessageSource: false
handlebars.prettyPrint: false
handlebars.infiniteLoops: false
NOTE: handlebars-guava-cache
is used as template cache implementation.
resolver
configuration allows on/off available handlebars value resolvers.
Here goes default configuration:
handlebars.resolver.javaBean: true
handlebars.resolver.map: true
handlebars.resolver.method: false
handlebars.resolver.field: false
More information about value resolvers can be found on Using the ValueResolver.
Set handlebars template cache by @Bean
of type TemplateCache.
Set handlebars template loader by @Bean
of type TemplateLoader.
handlebars-spring-boot-starter is published under Apache License 2.0.