Javascript Templates
I’m working on some pure-javascript applications (namely, the hCard creator, hCalendar creator and hReview creator (and soon another, super-secret project)) and need to do some enhancement to the markup they produce. Up until this point, I(we)’ve been building all the markup by concatenating strings together. However, this will only go so far.
When talking about the need for templating languages with some people (Simon? someone else?) at XTech, the phrase that kept coming up was “you can only get so far by glueing strings together.” At some point you need a stronger, more flexible approach, especially when dealing with markup.
So, I’ve started using TrimPath’s template library. It seems pretty nice so far. I know there have been other javascript templating efforts, but none seem to have much traction. Is there anything else worth trying?

August 30th, 2006 at 12:18 am
[...] n up to a point. Tim Bray is on to something when he talks about Ajax’s real upside. You can only get so far by glueing strings together. DOM manipulation is un [...]
November 18th, 2006 at 1:26 pm
Check out Jemplate, its based on Perl’s Template Toolkit:
http://search.cpan.org/dist/Jemplate/lib/Jemplate.pm
December 4th, 2006 at 7:14 am
Another JavaScript template engine is “Ajax Pages” (http://ajax-pages.sourceforge.net/). It has the advantage of being very simple and “to the point”.
October 4th, 2007 at 2:24 pm
Very simple one - under 100 lines for the whole engine - jMVC
http://blog.codeville.net/2007/10/04/rich-javascript-mvc-user-interfaces-with-jmvc/
Neat and simple…
December 18th, 2007 at 9:24 am
Check out embeddedjs.com for a very complete solution.
It has rails like view helpers.
It can include JS lint and provide line numbers/error handling.
It can load, process and cache template files.
Almost all functionality can be encapsulated in one line.
March 5th, 2008 at 1:49 pm
I tried embedded.js except that it hung trying to load my template from the server. Why? Because I was already in an Ajax call (a Drag n’ Drop scriptaculous function, actually).
I don’t like TrimPath’s use of Velocity-like syntax, and that bit failed to compile in a JSP on a default Jetty instance because it’s too much like JSTL.
So I rolled my own that’s pure JSP-like but without the Ajax requirement.
Better JavaScript Templates