While you have identified the problem yourself already, the proposed solution is not a good one.
You should not use global variables that are set somewhen and use promises just for propagating changes, but the promises should represent these values. This leads to a better, functional programming style.
In your case:
var tpl = {
…
templatePromise: null,
load: function(template) {
this.templatePromise = $.get(this.templateUrl + template).then(function(response) {
console.log(this.template);
//Outputs the desired value
return response;
});
return this;
},
attachTo: function(el) {
$.when(this.templatePromise).done(function(template) {
// get the template here: ^^^^^^^^
console.log(template);
});
}
…
}