I have a mustache template with a lambda looking like this:
{{#myfunc}}myvalue{{/myfunc}}
It is precompiled by hogan.js to look like this:
define(['hogan'],
function (Hogan) {
var template = new Hogan.Template(function (c, p, i) {
var _ = this;
_.b(i = i || "");
if (_.s(_.f("myfunc", c, p, 1), c, p, 0, 11, 18, "{{ }}")) {
_.rs(c, p, function (c, p, _) {
_.b("myvalue");
});
c.pop();
}
return _.fl();;
});
return function (context, partial, indent) {
return template.render(context, partial, indent);
};
});
I render the template using a Marionette.ItemView passing the lambda function into the Backbone.Model like this:
myfunc: function (key) { console.log("key", key); }
The weird thing: The function myfunc will be called and log to the console but it isn't passed a key by the template. I read about Hogan not supporting Lambda in precompiled mode (about a year ago - i guess this is fixed) - but if so how does it happen, that myfunc is called at all?
I put some debugging into my vendor/hogan.js lib - it looks like hogan cannot see the value between lambda-tags (here: myvalue).
Anyone seen this before?
My investigation:
the problem occurs only while using grunt plugins such as grunt-hogan or grunt-templates-hogan.
If compile a template before rendering inline in script with Hogan.compile() the issue is resolved.
I create a small project on github, because jsfiddle doesn't allow to use grunt and link it to issue https://github.com/twitter/hogan.js/issues/225.
Project: https://github.com/ssuvorov/hogan-issue
My solution was to replace lambdas with necessary object fields. I mean prepare data with all necessary information before rendering.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With