Mustache Templating
Reference:
http://mustache.github.com/mustache.5.html
http://net.tutsplus.com/tutorials/javascript-ajax/quick-tip-using-the-mustache-template-library/
HTML
<script src="http://github.com/janl/mustache.js/raw/master/mustache.js"></script>
<div id="mydiv"></div>
<script id="template" type="text/html">
<h1>nor {{data.name}} </h1>
<h2>you are {{data.age}} years old</h2>
{{#welcomeFunction}}
<span>{{message}}</span>
{{/welcomeFunction}}
<p>
<span> here comes custom </span>
<p>
{{customeWelcomeFunction}}
</script>
JavaScript
var data, template, html, custom;
custom={
name:'Corneliu',
age:'18'
}
formater=new function(name, message){
return 'Hy '+name+', '+message
}
data = {
data: custom,
test: 'test',
message:'you are welcome',
welcomeFunction: function () {
return function (text, render) {
return "<b>" + render(text) + "</b>";
}
},
customeWelcomeFunction: function () {
return data.data.custom.name
//return that.formater('a1', 'b1')
}
}
template = document.id("template").get('html');
html = Mustache.render(template, data);
document.id("mydiv").set('html', html);