Freemarker vs. Velocity

Tony the Pony picture Tony the Pony · Nov 9, 2010 · Viewed 26k times · Source

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?

Answer

Nathan Bubna picture Nathan Bubna · Nov 10, 2010

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.