Patroon: Another JavaScript Templating Solution
Written by on September 15th, 2008 in Uncategorized.
Matthias Georgi has posted the release of Patroon, his new templating system that uses JavaScript. It joins other solutions such as using Django via JavaScript (e.g. Dojo let’s you do that), TrimPath, and more.
The way it works is simple. You setup the data that you will be able to access in the template:
JAVASCRIPT:
-
-
var data = {
-
comment: [{
-
date: “2008-09-07 12:28:33″,
-
name: “David Beckham”,
-
website: “beckham.com”,
-
text: “I watched the euro finals on tv…”
-
}, {
-
date: “2008-09-07 14:28:33″,
-
name: “Tuncay”,
-
website: “”,
-
text: “Me too”
-
}]
-
};
-
Then you create an HTML template with variables a la {variablename}:
HTML:
Then you run the template and put the output back into the DOM:
JAVASCRIPT:
-
-
// The comments template will be removed from the DOM!
-
var template = new Template(‘comments-template’);
-
-
// not using a library
-
-
// template will result in a new DOM node
-
var result = template.expand(data);
-
-
// insert the resulting node into the comments container
-
var container = document.getElementsByClassName(‘comments’)[0];
-
container.appendChild(result);
-
-
// using jquery
-
$(‘.comments’).expand(template, data);
-
Source: Ajaxian » Front Page
Original Article: http://feeds.feedburner.com/~r/ajaxian/~3/393165653/patroon