I'm a big fan of separating the business logic and the presentation layer. This can be easily done by PHP, ROR, Java, etc. but when you try to do it in JavaScript it's not obvious how to do it, or which is the best way.
I've researched a lot on the topic and found two schools that is used by JS template libraries:
- Template language parsing
- Procedural approach
Both are great ways to generate, it only depends on your needs.
Here are some projects worth noting:
Using it is easy:
var tpl = new Jtl( document.getElementById('tpl').value );
var data = {
namelist :[
{name : 'Johnnn' , job : 'Director',topicID:[1,2,3,4]},
{name : 'Nick' , job : 'Manager',topicID:[4,3,6,5],test : 'Anything'},
{name : 'Tony', topicID:[5,66,7]}
]
};
document.getElementById('destination').innerHTML = tpl.render( data );
{%for people in namelist%}
File attached to post: javascript_template_engine.zip
All rights reserved, ©2008-2010 - Built on CodeIgniter framework - Konami codes - Mostly Valid XHTML 1.1 - Valid CSS 2.1