Skip to content

Instantly share code, notes, and snippets.

@bentranter
Created March 11, 2015 23:09
Show Gist options
  • Save bentranter/cef7a7e76d5f68a926ff to your computer and use it in GitHub Desktop.
Save bentranter/cef7a7e76d5f68a926ff to your computer and use it in GitHub Desktop.
Render templates from a collection using Exoskeleton and Microtemplate
<script id='itemTemplate' type='text/template'>
<li><%= someValue %></li>
</script>
<ul id='item'></ul>
(function() {
'use strict';
window.WhatEverView = Backbone.View.extend({
el: '#item',
template: microtemplate(document.querySelector('#itemTemplate').innerHTML),
initialize: function() {
this.collection.fetch();
this.listenTo(this.collection, 'sync', this.render);
},
render: function() {
var self = this;
this.collection.forEach(function(model) {
self.el.innerHTML += self.template(model.attributes);
});
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment