Saturday, November 18th, 2006


Category: JavaScript, Library

Walter Higgins is a believer in having a template language for you to use within JavaScript. He had issues with TrimPath’s templating system, so he ended up creating SXOOP.template:

Writing TinyTemplate in Perl was a breeze and the codebase is tiny. I used a similar approach to writing SXOOP.template which resulted in a tiny codebase for the Javascript version too.

What need for Javascript Templating you ask ?

Well, JSON gives Javascript Templating something to do. More and more webservices are supporting JSON.
What’s more; if you combine SXOOP.template with this brilliant XML javascript library, then suddenly javascript templating becomes 1000 times more useful (most existing WebServices use XML). You can mix and combine XML data sources (like the ubiquitous RSS and less well known formats like OPML) and use them to construct Human-readable web-pages without resorting to XSLT.

Example template usage

This example snippet is taken from the poor mans blog template

  1. <!-- bookmarks template -->
  2. <textarea id="bookmarks" style="display:none;">
  3. <ol>
  4.   [:
  5.     for (var i = 0; i < $_&#91;"rdf:RDF"&#93;.item.length; i++) {
  6.         var bookmark = $_&#91;"rdf:RDF"&#93;.item&#91;i&#93;;
  7.  :&#93;
  8.  <li><h4><a href="[:= :]">[:= bookmark.title :]</a></h4>
  9.      <p>[:= bookmark.description :]</p>
  11.   [: } // end for loop :]
  12. </ol>
  13. </textarea>

The entire library is here at 82 lines of commented code.

Posted by Dion Almaer at 7:48 am

3.3 rating from 32 votes


Comments feed TrackBack URI

why not just use standard javascript to achive much the same thing without the 82 lines of code? Or am i missing the point?

Comment by Matt Oakes — November 18, 2006

Think about developing large and flexible RIAs. When their behaviour depends heavily on external data sources (via RSS, OPML, JSON ans alike) templates come in handy. They’re also quite helpful in designers+developers cooperation.

Comment by Tom Sieron — November 20, 2006

actually, i do not like php.
the code page is not easy to read at all.

Comment by job — September 12, 2007

Leave a comment

You must be logged in to post a comment.