Skip to content

Instantly share code, notes, and snippets.

@searls
Created January 26, 2011 04:09
Show Gist options
  • Save searls/796211 to your computer and use it in GitHub Desktop.
Save searls/796211 to your computer and use it in GitHub Desktop.
fun with underscore templates!
<script id="someTemplate" type="text/html">
<span class="warning-image"></span><p>{{ error }}</p></span>
</script>
------
(function($){
$.fn.renderTemplate = function(name,context) {
$(this).html(_($('#'+name).html()).template(context));
return this;
};
})(jQuery);
--------
$('#container').renderTemplate('someTemplate',{error: 'party time!'});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment