Async Loading of Templates in Backbone
window.loadTmpl = (function () {
var templates = {}, temps, buildObj, getTemplate;
$.get('templates/templates.html', function(html) {
buildObj( html );
});
buildObj = function (html) {
temps = $( html ).children('script');
$.each( temps, function (index, template) {
templates[template.id] = template.innerHTML.trim();
});
};
getTemplate = function (temp) {
return ( temp in templates ) ? templates[temp] : null;
};
return getTemplate;
}());
Written by Kurtis Kemple
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Templates
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#