I'm trying to write a function that will give me a compiled handlebars template (I have all my templates in separate files) using an ajax call to get the template and compile it for use, but I need to use a promise so I can actually use it.
function getTemplate(name){
$.get('/'+name+'.hbs').success(function(src){
var template = Handlebars.compile(src);
//can't return the template here.
});
}
How do I do this with promises so I can do something like:
$("a").click(function(e){
getTemplate('form').done(function(template){
$("body").append(template({
name: "My Name"
})
);
});
});