I'm trying to decide between Freemarker and Velocity to use as a template engine, any advantages/disadvantages you see regarding each?
Any alternatives that I should look at instead?
Velocity and FreeMarker are two templating languages that can both be used as view technologies within Spring MVC applications. The languages are quite similar and serve similar needs and so are considered together in this section.
In the pursuit of comparison between FreeMarker , Thymeleaf, Groovy and Mustache, FreeMarker has the upper hand in performance. However, Thymeleaf wins the battle overall.
Velocity templates were deprecated in Liferay Portal 7.0 and are now removed in favor of FreeMarker templates in Liferay DXP 7.2.
FreeMarker is a template engine, written in Java, and maintained by the Apache Foundation. We can use the FreeMarker Template Language, also known as FTL, to generate many text-based formats like web pages, email, or XML files.
Velocity and Freemarker are both quite capable. Don't agonize over the choice. They have fairly different priorities behind their design, so once you get beyond basic templating, their feature-sets are hard to compare. Velocity's syntax is simpler and more distinct, Freemarker's heavier syntax allows them to support JSP libs. Velocity gives more freedom and ultimately more features through add-on projects like VelocityTools. Freemarker provides much better native whitespace handling, recent Velocity releases provide more interesting content controls (#define, #evaluate, #[[literal block]]#).
As for performance, Velocity has made great gains in recent years, except perhaps in the initial template parse. But for any sane app where performance matters, you should have both engines set to cache templates and only parse once, making this less of an issue. In general, you will find that your performance with either engine depends far more upon the nature of your templates than the differences between the engines.
StringTemplate is also respectable, though they are MVC nazis and can't match Velocity or Freemarker for features. ;) Your potential disappointment there is a bit higher than for either of the more popular template engines, of which neither is likely to disappoint much. Just grab one and go.
I prefer FreeMarker. I love the documentation, I can always find what I need. Overall I just think it is very powerful.
String Template is another alternative.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With