Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Freemarker vs. Velocity [duplicate]

Tags:

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?

like image 478
Tony the Pony Avatar asked Nov 09 '10 20:11

Tony the Pony


People also ask

What is velocity and FreeMarker?

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.

Which is better Thymeleaf or FreeMarker?

In the pursuit of comparison between FreeMarker , Thymeleaf, Groovy and Mustache, FreeMarker has the upper hand in performance. However, Thymeleaf wins the battle overall.

Is Velocity template deprecated?

Velocity templates were deprecated in Liferay Portal 7.0 and are now removed in favor of FreeMarker templates in Liferay DXP 7.2.

What is FreeMarker used for?

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.


2 Answers

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.

like image 62
Nathan Bubna Avatar answered Sep 17 '22 13:09

Nathan Bubna


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.

like image 25
Andy Avatar answered Sep 18 '22 13:09

Andy