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?

6 Responses to “Javascript Templates”

  1. Javascript templating with SXOOP.template « Sxoop Journal Says:

    […] 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 […]

  2. David A. Coffey Says:

    Check out Jemplate, its based on Perl’s Template Toolkit:
    http://search.cpan.org/dist/Jemplate/lib/Jemplate.pm

  3. David Finley Says:

    Another JavaScript template engine is “Ajax Pages” (http://ajax-pages.sourceforge.net/). It has the advantage of being very simple and “to the point”.

  4. codeville Says:

    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…

  5. Justin Meyer Says:

    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.

  6. Mark Turansky Says:

    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