resig
JavaScript Micro-Templating from John Resig JavaScript Micro-Templating
Super-simple templating function that is fast, caches quickly, and is easy to use in the browser or nodejs.
You would use it from script like so:
var resig = ;var results = document;resultsinnerHTML = ;
You could pre-compile the results for later use. If you call the templating function with only an ID (or a template code) then it’ll return a pre-compiled function that you can execute later:
var userTmpl = html = '';for var i = 0; i < userslength; i++ html += ;
Finally, here's the code in full:
// Simple JavaScript Templating// John Resig - http://ejohn.org/ - MIT Licensed{ var cache = {}; this{ // Figure out if we're getting a template, or if we need to // load the template - and be sure to cache the result. var fn = !/\W/ ? cachestr = cachestr || : // Generate a reusable function that will serve as a template // generator (and which will be cached). "obj" "var p=[],print=function(){p.push.apply(p,arguments);};" + // Introduce the data as local variables using with(){} "with(obj){p.push('" + // Convert the template into pure JavaScript str + "');}return p.join('');"; // Provide some basic currying to the user return data ? : fn; };};