As suggested by RoccoC5, you can define a small plugin that will select your remote template and then add its contents to the script tag in the head:
(function ($) {
$.loadTmpl = function (url, name) {
return $.get(url).success(function (content){
$("head").append($('<script/>', {
id: name,
type: 'text/template'
}).html(content));
});
};
}(jQuery));
and use it with:
$.loadTmpl('hi.html', 'hi').done(function () {
$('#hi').tmpl({name: 'Tom'}).appendTo('body');
});
or
$.when(
$.loadTmpl('foo.html', 'foo'),
$.loadTmpl('bar.html', 'bar'),
...
).done(function () {
});
I hope for this help.
source
share