Created
April 7, 2013 15:53
-
-
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.
This file contains 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
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