Create a gist now

Instantly share code, notes, and snippets.

anonymous /templateLoader.js
Created Jul 11, 2012

What would you like to do?
External Template Loader for Kendo UI
var templateLoader = (function($,host){
//Loads external templates from path and injects in to page DOM
return{
loadExtTemplate: function(path){
var tmplLoader = $.get(path)
.success(function(result){
//Add templates to DOM
$("body").append(result);
})
.error(function(result){
alert("Error Loading Templates -- TODO: Better Error Handling");
})
tmplLoader.complete(function(){
$(host).trigger("TEMPLATE_LOADED", [path]);
});
}
};
})(jQuery, document);

I'd like to suggest an improvement, what about adding a triggername parameter to loadExtTemplate?
So that multiple templates loaded events could be handled?

This was nice to begin with, but is not practical for situations where you have separated your template ("Views") into several files.

  • should accept an "array" of templates
  • event should be triggered only after all templates were loaded
  • templates should have their own "Name" to reference easily
  • the function will not depend on the template to have the "script" tag, rather user will write a clean template (better editable by IDE's)

Also, it uses a deprecated jQuery calls which are to be removed at some point...

I've re-written a function to address this issues at https://gist.github.com/amirgalor/8705653

it accepts a "JSON" array of {path: "path to file", tag: "script's tag to attach to dom"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment