Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,18 @@ var Hogan = {};
var oldTags = this.options.delimiters;

this.options.delimiters = tags;
this.b(this.ct(coerceToString(func.call(cx, text, ctx)), cx, partials));
this.b(this.ct(coerceToString(func.call(cx, text, ctx)), ctx, partials));
this.options.delimiters = oldTags;

return false;
},

// compile text
ct: function(text, cx, partials) {
ct: function(text, ctx, partials) {
if (this.options.disableLambda) {
throw new Error('Lambda features disabled.');
}
return this.c.compile(text, this.options).render(cx, partials);
return this.c.compile(text, this.options).ri(ctx, partials);
},

// template result buffering
Expand Down Expand Up @@ -243,7 +243,7 @@ var Hogan = {};
var result = func.call(cx);

if (typeof result == 'function') {
return this.ct(coerceToString(result.call(cx)), cx, partials);
return this.ct(coerceToString(result.call(cx)), ctx, partials);
}

return result;
Expand Down
17 changes: 17 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,23 @@ test("Undefined Return Value From Lambda", function() {
is(s, "abcdef", "deal with undefined return values from lambdas.")
});

test("Key from parent context should resolve in lambda", function() {
is(Hogan.compile(
'{{#a}}' +
'{{#lambda}}{{#a}}{{b}}{{/a}}{{/lambda}}' +
'{{/a}}'
).render({
a: {
b: 'val'
},
lambda: function() {
return function(text) {
return text;
};
}
}), 'val');
});

test("Sections with null values are treated as key hits", function() {
var text = "{{#obj}}{{#sub}}{{^test}}ok{{/test}}{{/sub}}{{/obj}}";
var t = Hogan.compile(text);
Expand Down