/ Published in: JavaScript
Simple templating for innerHTML functions. Parses an input string (tmpl) for %(NAME) tokens, accepts an object (ns) as data and returns an output string.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function RND(tmpl, ns) { var fn = function(w, g) { g = g.split("|"); var cnt = ns[g[0]]; for(var i=1; i < g.length; i++) cnt = eval(g[i])(cnt); return cnt || w; }; return tmpl.replace(/%(([A-Za-z0-9_|.]*))/g, fn); }