Skip to content

Instantly share code, notes, and snippets.

@cowboy
Created June 15, 2010 18:32
Show Gist options
  • Save cowboy/439479 to your computer and use it in GitHub Desktop.
Save cowboy/439479 to your computer and use it in GitHub Desktop.
// Uber-basic templating.. good? bad? ugly?
function interpolate( str, data ) {
data = data || window;
return !str
? ''
: str.replace( /{([^}]*)}/g, function(a,b){
return data[ b ] || '';
});
};
var data = { foo: 123, bar: 456 };
interpolate( 'http://example.com/{foo}/{bar}/', data ); // "http://example.com/123/456/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment