Skip to content

Instantly share code, notes, and snippets.

@davetheninja
Created April 13, 2012 14:40
Show Gist options
  • Save davetheninja/2377348 to your computer and use it in GitHub Desktop.
Save davetheninja/2377348 to your computer and use it in GitHub Desktop.
Display Models for Backbone/Underscore template
window.MyView = Backbone.View.extend({
...
render: function() {
var html = My.Namespace.Templates.apply("template_name", new MyDisplayModel({
model: this.model,
assHatOfTheWeek: "asshatting on alcohol at confs"
}));
this.$el.html(html);
...
return this;
}
});
window.MyDisplayModel = new JS.Class("MyDisplayModel", {
initialize: function(args) {
this.model = args.model;
this.someOtherThing = args.someOtherThing;
},
ultimateAsshatPoints: function() {
return this.assHatOfTheWeek == "asshatting on alcohol at confs";
},
fullName: function() {
return this.model.get("first_name") + " " + this.model.get("last_name");
}
})
// template
<h1>Something</h1>
<% if (this.ultimateAsshatPoints()) { %>
<p>WE HAVE OUR WEENER! and his name is <% this.fullName() %></p>
<% } %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment