diff --git a/lib/template.js b/lib/template.js index 14f396d..482914a 100644 --- a/lib/template.js +++ b/lib/template.js @@ -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 @@ -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; diff --git a/test/index.js b/test/index.js index ec0777e..07683b7 100644 --- a/test/index.js +++ b/test/index.js @@ -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);