Skip to content

Instantly share code, notes, and snippets.

@abachuk
Last active December 18, 2015 20:39
Show Gist options
  • Save abachuk/5841432 to your computer and use it in GitHub Desktop.
Save abachuk/5841432 to your computer and use it in GitHub Desktop.
<!-- Main script file -->
<!-- when JSON object is received it's passed to template (id of script tag) -->
<!-- posts in the end is JSON object we received from AJAX -->
var template = _.template( $("#posts_template").html(), posts );
<!-- in HTML document -->
<!-- emplty placeholder -->
<div id="posts-container"></div>
<!-- compiled template adds html to empty placeholder -->
<script type="text/template" id="posts_template">
<ul>
<% _.each(posts, function(post){ %>
<li><%= post.title %></li>
<% }); %>
</ul>
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment