Created
November 20, 2015 15:06
-
-
Save nicocedron/a7f02338a591f90e923c to your computer and use it in GitHub Desktop.
Simple Template
This file contains hidden or 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
window.templates = {} | |
window.SimpleTemplate = (template, data)-> | |
if !window.templates[template] | |
window.templates[template] = template | |
return template.replace /\{([a-zA-Z0-9_\.-]*)\}/ig, (x,s)-> | |
return eval('data.'+s) |
This file contains hidden or 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
<script id="templateTest"> | |
Hola {name}, | |
<br> | |
{message} | |
</script> |
This file contains hidden or 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
template = $('#templateText').html(); | |
resp = SimpleTemplate template, {name: 'Nico', message: 'Blablablabla'} | |
console.log resp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment