Created
March 9, 2010 00:52
-
-
Save ehynds/326014 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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