Skip to content

Instantly share code, notes, and snippets.

@toddself
Created December 3, 2012 13:03
Show Gist options
  • Save toddself/4194920 to your computer and use it in GitHub Desktop.
Save toddself/4194920 to your computer and use it in GitHub Desktop.
default render method
MyBaseView = Backbone.View.extend({
tpl_name: '',
render: function(){
var dfd = $.Deferred();
var template_context = this.model;
if(_.isUndefined(template_context) || _.isFunction(template_context)){
template_context = new (Backbone.Model.extend({}));
}
if(this.id) this.$el.attr('id', this.id);
var that = this;
dust.stream(this.tpl_name, template_context.toJSON())
.on('data', function(data){
that.$el.html(data);
if(!('placeholder' in document.createElement('input'))){
that.$('input').placeholder();
that.$('textarea').placeholder();
}
})
.on('end', function(){
dfd.resolve();
that.trigger('template:rendered');
})
.on('error', function(err){
dfd.reject();
that.trigger('template:error');
});
return dfd;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment