Hadlebars.java – How to use it as Server side Template Engine?

handlebars.java is a server-side Java template engine like velocity, freemaker, etc. It follows the syntax of Mustache spec. The main goal of handlebar.java is to reuse the same templates at client side and server side. In this article, we will see how to use Handlebars.java along with Spring framework. I have used Spring Boot for the demonstration. Follow the below steps to set up and run the handlebars.java

Step 1:

Include the handlebars.java implementation in the pom.xml

com.github.jknack
handlebars
4.0.5

As we are going to use JSON as the data to be rendered with the handlebars template, we will include handlebars JSON helper in the classpath.

I included the above code in org.smarttechie.controller.HandlebarsDemoController . Just run the org.smarttechie.HandlebarsjavaDemoApplication and send the request to /demo/home to see the rendered home page handlebar template. The source code created for this example is available on GitHub. Download it and explore more about the handlebars java implementation.