Skip to content

Instantly share code, notes, and snippets.

@akulubala
Created January 24, 2016 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akulubala/4d4e5868eeaef33a5c62 to your computer and use it in GitHub Desktop.
Save akulubala/4d4e5868eeaef33a5c62 to your computer and use it in GitHub Desktop.
underscore template usage
var tpl = _.template($("#template_errors").html(),{variable: 'items'});// define variable to retrive
var html = tpl(response.responseJSON); //pass datas to be loop
$("#js-form").prepend(html);
// template to use
<script type="text/template" id="template_errors">
<div class="error-list">
<ul>
<% _.each(items,function(item,key,arr) { %>
<li>
<span><%= item %></span>
</li>
<% }); %>
</ul>
</div>
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment