To be honest, I started with Thymeleaf (as it’s the most compelling option). Later, I switched to FreeMarker.
I worked a lot with PHP, Rails, and ASP.NET (MVC3+ with Razor). One thing all three of these platforms have in common is their allowance of extreme obsession over the HTML output. You can control each and every character of the final rendered HTML that comes out.
I like that. It allows you to easily configure and flex your application (CSS can be hell when you can’t even control the HTML), and it allows you to write clean, simple, and concise HTML.
That, in my opinion, is why FreeMarker is “better” than Thymeleaf. It takes you away from verbose XHTML declarations for every view, and allows you to write just the pieces that need to be plugged into your template layout.
Here’s a summary of places that I saw FreeMarker “win”:
- Conditional Output: If I want to display something on a certain condition, in Thymeleaf, I need to wrap that content in a
DIVtag with a conditional on it. In FreeMarker, I can just write the condition out; the HTML stays smaller.
- Writing Text: In PHP, writing text is really easy: you just echo it out. In Thymeleaf, you need to put it in a tag (like a
th:utextfor unicode). In FreeMarker, you can just write out your text; no additional tag required.
- Bare-Bones Sections: Both technologies allow you to create a layout with sections, and define markup for that particular section on a particular page. In Thymeleaf, even the section declaration requires a bunch of XHTML markup; in FreeMarker, you only write exactly the HTML you display out. Simple and efficient.
This is a summary of why I chose FreeMarker over Thymeleaf, as an HTML maniac. It fits my needs quite well, and I’m happy with it. I hope it will serve me well in the future (and I have no qualms with switching over to something that works better if such a thing exists).