Skip to content

Instantly share code, notes, and snippets.

@ehynds
Created March 9, 2010 00:52
Show Gist options
  • Save ehynds/326014 to your computer and use it in GitHub Desktop.
Save ehynds/326014 to your computer and use it in GitHub Desktop.
// extremely basic templating with replace().
var
// template
template = '<div id="#{id}">#{text}</div>',
// object literal of replacement values
params = { id:10, text:'hi there' },
// html => <div id="10">hi there</div>
html = template.replace(/#\{(.*?)\}/g, function($1, $2){
return ($2 in params) ? params[$2] : '';
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment