Template Engine recommendations

EAPers,
I'm interested in recommendations on templating engines. What do you guys like and why? A quick scan reveals 9 open source template engines including Velocity, FreeMarker, and StringTemplate:
http://java-source.net/open-source/template-engines
In coming up with your open source template engine of choice, did you do any comparison shopping? :)

Thanks,
Jon

8 comments
Comment actions Permalink

I use Velocity. Its simple to use (in stand-alone as well as in servlet environments), fast and allows easy access to the underlying java app by direct calling public java methods from the template.

BTW.: Would be a nice feature to support the Velocity in IDEA, at least by allowing the supression of error messages for Velocity expressions like $x, $ and #if(...) .. #end in Velocity-template-files (which are often html- or xml-files with embedded Veclocity expressions, so if you use the html or xml file-type IDEA flags an error for every Velocity-call in the file).

karsten.

0
Comment actions Permalink

If you want fashionable and popular, use velocity. if you want functional, powerful, and useful, use freemarker.

0
Comment actions Permalink

You're sounding a little bit deprecative towards velocity, while I have overall good experiences with it. Can you explain why freemarker is so much more "functional, powerful, and useful"?

0
Comment actions Permalink

Actually, that's one of the nicest things I've ever heard Hani say about a popular open source project. Well, excepting Ant, and that's only as an excuse to bash Maven...

--Dave Griffith

0
Comment actions Permalink

It is a good thing that Hani can praise an opensource project at all, even if only by using it as a bludgeon on another opensource project. :)

Anyone out there favor StringTemplate?

0
Comment actions Permalink

I checked out StringTemplate some time ago and found it to complicated to use. While it has a nice concept (on paper), if you need a 'work-horse' template engine I don't recommend it, because it just don't fits good into most Java projects. If you simply want to get things done, velocity if less trouble.

0
Comment actions Permalink

An unusual approach, but with distinct advantages:
Embed Jetty or Tomcat and use jsp as your templates.
One big advantage is that refactoring will also consider your templates. We had a lot of fun keeping our velocity templates up-to-date in each release...

0
Comment actions Permalink

Hi. Well, I'm biased of course, but I find StringTemplate extremely simple. I dispute the "doesn't fit into most Java projects" comment. :) I didn't reinvent JSP as all other template engines did. No point in creating yet another Turing complete template engine when you have JSP. Anyway, you'll note that I have used StringTemplate to good effect building jGuru and other sites as well as lots of code generators. The new ANTLR parser generator uses StringTemplate, providing easy retargeting to new languages...just change the template file. A template engine with embedded logic / computations must cut/paste "code" to make a new target. There is a single CodeGenerator controller object that pulls from the model (my internal trees) and pushes to the view (templates).

Take a quick peek at an article I did on translating a simple dialect of C to Java, Python, and bytecodes...just by swapping in a new template. :)

http://www.codegeneration.net/tiki-read_article.php?articleId=77

StringTemplate's benefits aren't seen for small projects...well, ok it's pretty cool, but it's main benefit of enforced separation emerges when you are concerned about multiple site skins, maintenance, etc.. (or multiple code generation targets).

Plus the damn thing is tiny; <200k :) Full source, BSD license.

http://www.stringtemplate.org

Thanks for your time...

Terence

0

Please sign in to leave a comment.