Thursday, April 5th, 2007
MJT: JavaScript Templating Library
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.
-
-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
-
<script type="text/javascript"
-
src="http://mjtemplate.org/dist/latest/mjt.js"></script>
-
</head>
-
<body onload="mjt.run('top')">
-
<div id="top" style="display:none">
-
<!-- the template lives inside this div element -->
-
-
running mjt version $mjt.VERSION
-
</div>
-
</body></html>
-












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.
Damn, I am also about to release a templating library :(
This is another take on this. http://www.xindesk.com/jtemplate/default.asp
The main points is speed and freely mixing javascript with html.
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?
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.
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.
they already invented a technology just for this… XSLT
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).
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?
Here you can find another javascript template library, give it a try jstemplate
For those stuck in the dark ages of perl, jemplate (http://search.cpan.org/~ingy/Jemplate-0.20/lib/Jemplate.pm) is an interesting option; Especially, if you already use the perl template toolkit, since it uses the same template syntax.
I just released my try on javascript templating. please try this: zparse
how can I make a link??? http://zparse.net.tc