netzpirat/haml_coffee_assets — Issue #10: Template undefined in JST after being added earlier
Author: goodwink
Created: 2011-11-30 17:39:27+00:00
State: open

Here is a .hamlc template I am having trouble with:
```haml
%td= new Date(@transaction.get('posted_at')).toString('M/d/yyyy')
%td= @transaction.escape('description')
%td= @transaction.debit()
%td= @transaction.credit()
%td= @transaction.running_balance()
```

This compiles down to the final javascript template thus:
```javascript
(function() {
this.JST || (this.JST = {});
this.JST["transactions/show"] = (function() {
var _ref;
if ((_ref = window.JST) == null) {
window.JST = {};
}
window.JST['transactions/show'] = function(context) {
var fn;
fn = function(context) {
var c, e, o;
o = [];
e = HAML.escape;
c = HAML.cleanValue;
o.push("	" + (e(c(new Date(this.transaction.get('posted_at')).toString('M/d/yyyy')))) + "");
o.push("	" + (e(c(this.transaction.escape('description')))) + "");
o.push("	" + (e(c(this.transaction.debit()))) + "");
o.push("	" + (e(c(this.transaction.credit()))) + "");
o.push("	" + (e(c(this.transaction.running_balance()))) + "");
return o.join("\n");
};
return fn.call(HAML.context(context));
};
}).call(this);;
}).call(this);
```

I noticed that the template is null/undefined when I try to use it in my backbone view, so I started tracing back to see where it was getting set figuring I had the order of imports wrong or something. The interesting thing that I found was that the above javascript was getting called before my view code looked for the template and it was also adding the template to window.JST! When I put a breakpoint before the line that reads "}).call(this);;" (basically stopping just before the call to .call(this)) and check the value of window.JST['transactions/show'] it is the function as expected. If I step on more line however window.JST['transactions/show'] is now undefined.

This is my first hamlc template (I've been using ECO), so it's very likely I'm just doing something wrong, but I haven't been able to figure it out and any help would be greatly appreciated.