Skip to content

Instantly share code, notes, and snippets.

@ducin
Created April 7, 2013 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ducin/5331028 to your computer and use it in GitHub Desktop.
Save ducin/5331028 to your computer and use it in GitHub Desktop.
ICanHaz templates loader object - load all your templates after the website has been initially rendered. See http://symfony-world.blogspot.com/2013/04/managing-lots-of-icanhaz-templates.html for details on concatenating template files.
var TemplateLoader = {
path: 'templates/', // template files are stored in this directory
templates: ['file1', 'file2', 'file3'], // put all your template files here
fetchTemplate: function(path) {
$.ajax({
type: 'GET',
dataType: 'text',
async: false,
url: path
}).done(function(response) {
$('body').append(response);
});
},
fetchAllTemplates: function() {
var index;
for (index = 0; index < this.templates.length; ++index) {
this.fetchTemplate(this.path + this.templates[index] + '.ich');
}
ich.grabTemplates();
},
concatenated_templates: 'templates.ich', // this file includes all templates (concatenated)
fetchConcatenatedTemplates: function() {
this.fetchTemplate(this.concatenated_templates);
ich.grabTemplates();
}
}
// load all files separately:
TemplateLoader.fetchAllTemplates();
// or load the concatenated version:
TemplateLoader.fetchConcatenatedTemplates();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment