JavaScriptTemplates - the middle ground between DOM and InnerHTML
When creating applications with a lot of AJAX we're often confronted with a choice to either build up all new content through a gazillion lines of DOM code or 'cheat our way out' with the dreaded element.innerHTML. The DOM way is extremely tedious and time consuming while innerHTML is considered 'dirty' by many developers. I tend to agree with those developers.
Enter JavaScript Templates. A perfect 'best of both worlds' solution. Ever used Smarty? You'll feel right at home with it.
I'm using JST templates in a project at this very moment and I can tell you: it rocks! If time permits I'll try to write a small tutorial in the future but in the meanwhile just go check it out!

Affiliate program available
bookmarking
Commentary
Join the discussion! Leave a comment through the below!
Got something to add to this?
Feel free to leave a comment on this site. You can use Textile and Emoticons. Your email address is only used to show a gravatar. Please stay on-topic and use common decency. Spammers will be shot in front of a live studio audience.
If you plan on posting code, use pastebin please and post a URL to the code. The comment processing doesn't deal very well with code. Sorry for the inconvenience.
Human comment spammers: don't bother posting your crap here. Comments are moderated and I won't let any of your shit through.
Trackbacks
If you have an interesting related post on your own site you can leave a trackback. As they say: 'a little AJAX a day keeps the spammers away' which is why you'll have to click below to generate a trackback key. The key will be valid for 15 minutes and can be used only once.
At 11 May '06 - 12:07 Stoyan wrote:
At 11 May '06 - 12:57 Marco wrote:
You don’t wanna use that in your serverside view engine either now do ya? ;)
The template language used with this JST thing is as easy as Smarty! Like I said, it’s the perfect middle ground between tons of DOM code and ugly element.innerHTML = ‘shitload of concatenated crap’ :)
At 11 May '06 - 14:03 Stoyan wrote:
- forwards compatible – easier to hire people who know it (it’s widely accepted) then people who know a specific templating library – built in the browsers (inconsistently, of course, otherwise the life would be so boring), doesn’t need extra code to execute – features XPath and a bunch of other X’s – ... there must be more pros I can’t think of right now
At 11 May '06 - 14:21 Marco wrote:
But to look at your arguments:
1) Any programmer can learn this in about one hour
2) Isn’t generic javascript too?
3) XPath is a pro. I agree!
BUT: In order to use XSLT at all one has to actually first generate XML on the server which is something I personally hate to do unless it’s really necessary. Doing the XML thing right requires the tedious DOM coding on the server which sort of brings back the original reason why quite some people revert to using innerHTML
At 12 May '06 - 12:51 Montoya wrote:
I’ve been using it in a project and it’s great. I just format my data server side as XML and then call it through AJAX. It goes where I tell it to and does not use innerHTML.
Granted, it’s different from JST, but I just can’t understand how hidden textareas are anything other than a hack. Taconite’s parser seems safer and it does not bend the rules at all.
At 12 May '06 - 16:02 Marco wrote:
I don’t know Taconite. I’ll check it out!
As far as JST is concerned: I fetch the templates with an XmlHttpRequest object so I’m not dealing with the hidden textfield thing which is indeed a (dirty) hack.