Skip to content

Instantly share code, notes, and snippets.

@niceaji
Last active December 13, 2015 21:08
Show Gist options
  • Save niceaji/4975128 to your computer and use it in GitHub Desktop.
Save niceaji/4975128 to your computer and use it in GitHub Desktop.
//http://nodecellar.coenraets.org/
//util.js
window.utils = {
// Asynchronously load templates located in separate .html files
loadTemplate: function(views, callback) {
var deferreds = [];
$.each(views, function(index, view) {
if (window[view]) {
deferreds.push($.get('tpl/' + view + '.html', function(data) {
window[view].prototype.template = _.template(data);
}));
} else {
alert(view + " not found");
}
});
$.when.apply(null, deferreds).done(callback);
},
..
..
//main.js
utils.loadTemplate(['HomeView', 'HeaderView', 'WineView', 'WineListItemView', 'AboutView'], function() {
app = new AppRouter();
Backbone.history.start();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment