The net seems to be full of comparisons between Velocity and FreeMarker, and they seem to be reasonably equivalent. But there seems to be almost no comparisons between StringTemplate and FreeMarker!
So, what are the main differences between StringTemplate and FreeMarker?
My usage for them would be to generate HTML pages only. Out of the two, I would've expected FreeMarker to be the more suitable and more capable, as that seems to the more common one - but through a quick glance it seems that StringTemplate actually has more suitable features!
It would be great if someone who has used both would have time to comment - for the actual specifics, I can just read the documentation side by side, but I'd like something to get started with.
FreeMarker has all the essential features to generate HTML for most of the cases, and it is easier to learn. So it is not a bad idea if you want to use it. However, Thymeleaf is the way to go if you want to add custom functionality to your templates.
Comments: Comments are similar to HTML comments, but they are delimited by <#-- and --> . Comments will be ignored by FreeMarker, and will not be written to the output.
If you want to insert the value of an expression into a string, you can use ${...} (and the deprecated #{...} ) in string literals. ${...} in string literals behaves similarly as in text sections (so it goes through the same locale sensitive number and date/time formatting).
Template loaders are objects that load raw textual data based on abstract template paths like "index. ftl" or "products/catalog. ftl" . It's up to the concrete template loader if from where and how the template "files" are loaded.
I designed ST to build jGuru after getting sick of the "code in template" model of JSP. Velocity and friends (i.e., every other engine i think) give you more power than you need. I used basically four features to build jGuru.com (as described in paper). More features are unnecessary and lead you to entangle your model into the template. If you're building a one-off prototype, that's ok and any engine is fine. Code in templates is ok in that case since you don't care about maintenance.
Another thing people seem to ignore: how the hell can a graphics designer read code in templates? They can't. So, how can they work on the templates then? Even changing the order of some elements can break your model. You really need the separation to work in commercial environment, unless you want a site that looks like a coder built the html ;)
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