How to Use a Resig MicroTemplate
The JavaScript Resig micro templates where created by John Resig. He’s also the creator and developer of jQuery JavaScript library and the Dean of Open Source and the head of JavaScript development at Khan Academy. The Resig micro templates are JavaScript templates that create quick and easy to use templates for your JavaScript application building needs. Just place the Regis micro template into your JavaScript application or website to use it.
Instructions
-
-
1
Enter the script into the form you want to put the Resig micro template in. Use this script: “<script type="text/html" id="item_tmpl">
<div id="<%=id%>" class="<%=(i % 2 == 1 ? " even" : "")%>">
<div class="grid_1 alpha right">
<img class="righted" src="<%=profile_image_url%>"/>
</div>
<div class="grid_6 omega contents">
<p><b><a href="/<%=from_user%>"><%=from_user%></a>:</b> <%=text%></p>
</div>
</div>
</script>” -
2
Enter the Resig micro template into your form:
(function(){
var cache = {};
this.tmpl = function tmpl(str, data){
var fn = !/\W/.test(str) ?
cache[str] = cache[str] ||
tmpl(document.getElementById(str).innerHTML) :
new Function("obj",
"var p=[],print=function(){p.push.apply(p,arguments);};" +
"with(obj){p.push('" +
str
.replace(/[\r\t\n]/g, " ")
.split("<%").join("\t")
.replace(/((^|%>)[^\t]*)'/g, "$1\r")
.replace(/\t=(.*?)%>/g, "',$1,'")
.split("\t").join("');")
.split("%>").join("p.push('")
.split("\r").join("\\'")
+ "');}return p.join('');");
// Provide some basic currying to the user
return data ? fn( data ) : fn;
};
})();” -
-
3
Save your work.
-
1