Skip to content

Instantly share code, notes, and snippets.

@wheaties
Created November 2, 2013 17:08
Show Gist options
  • Save wheaties/7281152 to your computer and use it in GitHub Desktop.
Save wheaties/7281152 to your computer and use it in GitHub Desktop.
Handlebars Defered Template w/ Backbone example use case
//Assumes jQuery, produces a lazy load template function.
var Template = function(el){
var $el = $(el),
template = undefined;
//Compile template and store once.
return function(args){
if(!template){
template = Handlebars.compile($el.html());
}
return template(args);
}
}
//Defered Backbone View
var DeferedModelView = Backbone.View.extend({
model: Backbone.Model,
template: function(){
return '<div></div>'
},
render: function(){
var html = this.template(this.model.toJSON());
this.$el.html(html);
return this;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment