public
Created

Managing templates with Underscore template

  • Download Gist
example.coffee
CoffeeScript
1 2 3 4 5 6 7 8 9 10 11
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'
example.html
HTML
1 2 3 4
<script id='storyTemplate' class='template' type='text/template'>
<h1><%= title %></h1>
<p><%= content %></p>
</script>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.