Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Load underscore templates with jQuery $ajax()
window.renderTemplate = function(name, el, json)
{
var url = '/templates/' + name + '.html';
$.ajax({
url: url,
method: 'GET',
async: false,
dataType: 'html',
success: function(data) {
var tmpl = _.template(data);
$(el).html(tmpl(json));
}
});
}
// Implementing it in the backbone.
window.MyView = Backbone.View.extend({
el: $('#mainframe'),
render: function(eventName) {
renderTemplate('tmpl_name', this.el, {description: 'This is first template'});
return this;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.