Skip to content

Instantly share code, notes, and snippets.

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 ralphcrisostomo/3347753 to your computer and use it in GitHub Desktop.
Save ralphcrisostomo/3347753 to your computer and use it in GitHub Desktop.
using handlebars with backbone block collection
// Reference:
// http://stackoverflow.com/questions/7344982/questions-on-backbone-js-with-handlebars-js
var ArticleListView = Backbone.View.extend({
el: $('#main'),
render: function(){
var js = this.collection.toJSON();
var template = Handlebars.compile($("#some-template").html());
$(this.el).html(template({articles: js}));
return this;
}
});
// Sample Handlebars Template
/**
<script id="some-template" type="text/x-handlebars-template">
{{#each articles}}
{{this.title}}
{{/each}}
</script>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment