Created
March 2, 2012 16:20
-
-
Save andrewpthorp/1959425 to your computer and use it in GitHub Desktop.
Underscore.js errors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MYAPP = { | |
fetchTemplate: function(path, done) { | |
window.JST = window.JST || {}; | |
// Should be an instant synchronous way of getting the template, if it | |
// exists in the JST object. | |
if (JST[path]) { | |
return done(JST[path]); | |
} | |
// Fetch it asynchronously if not available from JST | |
return $.get(path, function(contents) { | |
var tmpl = _.template(contents); | |
JST[path] = tmpl; | |
done(tmpl); | |
}); | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SomeView = Backbone.View.extend({ | |
id: "temp-test", | |
template: "template.html", | |
render: function(){ | |
var self = this; | |
MYAPP.fetchTemplate(this.template, function(tmpl){ | |
self.$el.html(tmpl()); | |
if (_.isFunction(done)){ | |
done(self.el); | |
} | |
} | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<section class="benefits index"> | |
<img id="temp" src="assets/img/benefits-main.png" /> | |
</section> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment