Skip to content

Instantly share code, notes, and snippets.

@mklabs
Created July 16, 2011 20:00
Show Gist options
  • Select an option

  • Save mklabs/1086711 to your computer and use it in GitHub Desktop.

Select an option

Save mklabs/1086711 to your computer and use it in GitHub Desktop.
little template engine helper
function tmpl(s,d){return s.replace(/:([a-z]+)/g, function(w,m){return d[m];});}
// auto executing function
function tmpl(s,d){return s.replace(/:([a-z]+)/g, function(w,m){return w.replace(/.+/, d[m]);});}
/*
tmpl(':foo <p>:bar</p>', {foo: 'bar', bar: true})
> bar <p>true</p>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment