Return to Snippet

Revision: 828
at August 11, 2006 20:26 by mattgay


Initial Code
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);
}

Initial URL

                                

Initial Description
Simple templating for innerHTML functions. Parses an input string (tmpl) for %(NAME) tokens, accepts an object (ns) as data and returns an output string.

Initial Title
RND - simple template for innerHTML

Initial Tags
javascript, template

Initial Language
JavaScript