Thursday, April 5th, 2007

MJT: JavaScript Templating Library

Category: JavaScript, Library, Utility

The group behind Freebase have released MTJ, the templating library they created for their own use:

Mjt makes it very simple to take data from a web service and format it in a browser, with no server support. The templates are hosted and delivered as static HTML, and they are compiled and applied entirely in Javascript.

Mjt is particularly useful with services that return JSON values and accept a callback= parameter, such as the Freebase service and the Yahoo JSON API. With these services you can use mjt to build “mash-ups” that incorporate data from services on multiple hosts.

  1. <html><head>
  2. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
  3. <script type="text/javascript"
  4.        src=""></script>
  5. </head>
  6. <body onload="'top')">
  7. <div id="top" style="display:none">
  8.     <!-- the template lives inside this div element -->
  10.     running mjt version $mjt.VERSION
  11. </div>
  12. </body></html>

Posted by Dion Almaer at 6:01 am

2.6 rating from 13 votes


Comments feed TrackBack URI

I’m not a big fan of template markup that use this structure, because they generated invalid markup. It’s the main reason I’m not a big fan of Adobe’s Spry project.

Comment by Dan G. Switzer, II — April 5, 2007

Damn, I am also about to release a templating library :(

Comment by Rizqi Ahmad — April 5, 2007

This is another take on this.

The main points is speed and freely mixing javascript with html.

Comment by mikael bergkvist — April 5, 2007

I’ve been using TrimPath’s template library and it has worked out nicely. Can anyone describe what is different about this one? Speed? Language? etc?

Comment by Patrick Lightbody — April 5, 2007

I like the idea of templated language espeically if I can fix in the Ajax stuff.. it’s similar to JSTL in Java.

It will definitly help in lots of Ajax scenarios, however, if UI components like yahoo UI and what not can provide support for it, then it will truely take off.. that’s my perosnal opinion.

For example, i sure can use the template to gerneate a table, but what if i need sorting on the table, resize, drag and drop, etc.. it will be nice if a UI grid provides support for it.

Comment by Liming Xu — April 5, 2007

Just from a brief look, it seems very similar to TrimPath Javascript Templates. Looks like MJT is closer to being valid markup, which is kinda nice. It also has some Ajax built in, which may be nice or a waste depending on your situation.

Comment by Brian Reischl — April 5, 2007

they already invented a technology just for this… XSLT

Comment by dizzle — April 5, 2007

There’s NO overlap in functionality between this and XSLT. However, like several people pointed out earlier, both and TrimPath offer pretty much the same functionality. This has ideal usage when you don’t like either innerHTML or DOM manipulation.

The only problem, as also seen with TrimPath, is because of the ${..} syntax, this will collide with the Stripes framework (for those of us who speak Java and prefer Stripes over Struts).

Comment by Kevin Hoang Le — April 5, 2007

there isnt overlap? as far as i can tell both of them are mini-procedural languages embeddable in custom DOM element attributenames/elementnames. theres a million of these templating languages. this one is neat since its built for JSON instead of XML, but otherwise, its still a subset of javascript hacked into custom attrs – unless you really need to let dreamweaver users edit the templates.

im finding it hard to find good documentation on E4X, but i think its the same idea, only you get the full language, instead of wahtever functions the author decided to expose into the mjt attr->func space?

Comment by carmen — April 5, 2007

Here you can find another javascript template library, give it a try jstemplate

Comment by wezzy — April 5, 2007

For those stuck in the dark ages of perl, jemplate ( is an interesting option; Especially, if you already use the perl template toolkit, since it uses the same template syntax.

Comment by Jason Crowther — April 6, 2007

I just released my try on javascript templating. please try this: zparse

Comment by Rizqi Ahmad — April 7, 2007

how can I make a link???

Comment by Rizqi Ahmad — April 7, 2007

Leave a comment

You must be logged in to post a comment.