22

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?

Tony the Pony
  • 40,327
  • 71
  • 187
  • 281

5 Answers5

36

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.

Nathan Bubna
  • 6,823
  • 2
  • 35
  • 36
8

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.

domih
  • 1,440
  • 17
  • 19
Andy
  • 8,841
  • 8
  • 45
  • 68
  • 2
    Again, that comparison is out of date and only compares the base features, ignoring Velocity's various powerful add-on projects. It is no credit to the freemarker community that they do not update it. – Nathan Bubna Nov 10 '10 at 15:37
  • @Nathan Bubna - I haven't really used velocity in sometime, what exactly is out of date on that comparison? – Andy Nov 10 '10 at 15:55
  • The majority of it, more than i can point out here. It's based on Velocity 1.2, which was like 9 years ago. Velocity 1.7 is in beta and soon to be final. It also seems to imply that things like VelocityTools are "workarounds", which is hardly a fair assessment. – Nathan Bubna Nov 11 '10 at 18:02
5

It looks like this is a decent rundown of the comparison. Though, it is a few years old.

From the article:

In conclusion

Both FreeMarker and Velocity are very capable template engines. Velocity seems to enjoy a larger user base, probably due to the fact that it is part of the Apache project. As I've shown in this article, though, FreeMarker is the more sophisticated and faster of the two. In basic operations both template engines are almost similar, providing an API that is easy to understand.

Both Velocity and FreeMarker are fairly easy to integrate into an application and offer good performance on small templates. Velocity slows down when parsing larger templates, which you might take into account when choosing a template engine for your project.

javamonkey79
  • 17,443
  • 36
  • 114
  • 172
2

There is a lengthy comparison on the freemarker project page.

Never having worked with velocity, I can not meaningfully compare the two, but I was so satisfied with freemarker that I saw no reason to look beyond it.

meriton
  • 68,356
  • 14
  • 108
  • 175
  • 1
    That lengthy comparison was perhaps valid for Velocity 1.4, but Velocity has added much since then. And that comparison always refused to acknowledge the existence of the popular VelocityTools project that has always provided a wealth of features. – Nathan Bubna Nov 10 '10 at 15:16
  • 1
    Correction, that comparison was valid for Velocity 1.2. The majority of it is supported in Velocity now (though sometimes implemented differently), the majority of the remainder is supported with VelocityTools. And some of the "comparison" is just weird. Velocity doesn't need java-independent functions, when we support the java functions easily. – Nathan Bubna Nov 11 '10 at 18:10
  • The link to the "lengthy comparison" is dead – domih Dec 09 '15 at 09:13
1

Freemarker does not run on Android. Therefore, I'm currently converting my project to Velocity to make it compatible to mobile devices.