Over the past week, I spent some time looking at Java based template engines. Typically I need templating support for two areas:
- View Templates (For rendering views in your browser)
- Email Templates - with support for both HTML and Text emails
For email templates I had used the usual suspects such as Velocity and Freemarker in the past but both feel a tad heavy and old these days - Velocity's last release was in 2010! Eventually I settled for a simpler option a while back: StringTemplate, which as a library worked fairly okay.
As I had done some client-side templating using Mustache and Handlebars, I was intrigued inseeing Java implementations for both:
- jmustache - https://github.com/samskivert/jmustache
- mustache.java - https://github.com/spullara/mustache.java
- handlebars.java - https://github.com/jknack/handlebars.java
The nice thing about Mustache is that implementations are available for almost any programming language imaginable, which could be nice in case you have the need to maintain browser-bound and backend (Java) templates or in case you have multiple Java and non-Java application with templating needs.
For now I have chosen mustache.java. Looks like it is heavily used at Twitter. Depending on how willing you are towards enduring any type of logic in your templates, you may also want to check out Handlebars and the corresponding Java implementation. It is basically a super-set of Mustache, providing additional built-in helpers.
Lastly, for both Mustache and Handlebars there is support available for Spring MVC.
I have not used either support for Spring MVC, yet, though. In case you have used any of the mentioned options, please leave feedback to this blog.