twitter / hogan.js

A compiler for the Mustache templating language
http://twitter.github.io/hogan.js
Apache License 2.0
5.14k stars 431 forks source link

Lambda return values are only compiled with immediate context #219

Open dpatti opened 9 years ago

dpatti commented 9 years ago

Take this example:

var identity = function(a){ return a; };

var template =
  "{{#one}}" +
    "Two: {{#i}}{{two}}{{/i}}" +
  "{{/one}}";

var context = {
  one: {},
  two: 2,
  i: function(){ 
    return identity;
  }
};

console.log(hogan.compile(template).render(context));

If we run this as above, we get Two:. If we replace the {{#i}}{{two}}{{/i}} section with just {{two}}, we get the expected output of Two: 2. This seems unnatural to me and maybe even under-defined in the mustache spec, but is this the intended behavior?

sayrer commented 3 years ago

I think it probably is, but I'll check this again.