Created
September 12, 2011 14:45
-
-
Save mahemoff/1211442 to your computer and use it in GitHub Desktop.
Managing templates with Underscore template
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
templates = {} | |
$ () -> | |
$('.template').each (i,el) -> templates[el.id.replace('Template','')] = _.template(el.innerHTML) | |
.... | |
# LATER ON, HERE IS HOW WE USE THE TEMPLATE ... | |
.... | |
$('.storyContainer').html templates.story | |
title: 'holy crazy!' | |
content: 'an amazing story' |
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
<script id='storyTemplate' class='template' type='text/template'> | |
<h1><%= title %></h1> | |
<p><%= content %></p> | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment