Skip to content

Instantly share code, notes, and snippets.

@kurtisdunn
Last active November 6, 2015 02:46
Show Gist options
  • Save kurtisdunn/09484c10cc8b9b5200d0 to your computer and use it in GitHub Desktop.
Save kurtisdunn/09484c10cc8b9b5200d0 to your computer and use it in GitHub Desktop.
Backbone.js Views - Template Loader.
fetchTemplates: function() {
var that = this;
var templatesCollection = new TemplatesCollection();
switch (window.location.pathname) {
case '/':
templatesCollection.fetch({
url: '/api/template/home',
success: function(rsp) {
//Set Template
templateName = 'Home';
that.renderMainContent(rsp.findWhere({
'template_title': "Home"
}));
}
});
break;
default:
templateName = window.location.pathname.toString();
templatesCollection.fetch({
url: '/api/template' + window.location.pathname,
success: function(rsp) {
templateName = window.location.pathname.substring(1);
that.renderMainContent(rsp.findWhere({
'template_desc': window.location.pathname.substring(1)
}));
},
});
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment