From 2a851067b99c3932e471f5fc1a2d40dc25a084c4 Mon Sep 17 00:00:00 2001 From: kpdecker Date: Sat, 1 Aug 2015 15:48:16 -0500 Subject: [PATCH] Add with block parameter support Fixes #1042 --- lib/handlebars/base.js | 9 ++++++--- spec/builtins.js | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/handlebars/base.js b/lib/handlebars/base.js index a1847fc4b..c2f14eb4d 100644 --- a/lib/handlebars/base.js +++ b/lib/handlebars/base.js @@ -194,13 +194,16 @@ function registerDefaultHelpers(instance) { let fn = options.fn; if (!Utils.isEmpty(context)) { + let data = options.data; if (options.data && options.ids) { - let data = createFrame(options.data); + data = createFrame(options.data); data.contextPath = Utils.appendContextPath(options.data.contextPath, options.ids[0]); - options = {data: data}; } - return fn(context, options); + return fn(context, { + data: data, + blockParams: Utils.blockParams([context], [data.contextPath]) + }); } else { return options.inverse(this); } diff --git a/spec/builtins.js b/spec/builtins.js index 46d70baac..959874326 100644 --- a/spec/builtins.js +++ b/spec/builtins.js @@ -47,6 +47,10 @@ describe('builtin helpers', function() { var string = '{{#with person}}Person is present{{else}}Person is not present{{/with}}'; shouldCompileTo(string, {}, 'Person is not present'); }); + it('with provides block parameter', function() { + var string = '{{#with person as |foo|}}{{foo.first}} {{last}}{{/with}}'; + shouldCompileTo(string, {person: {first: 'Alan', last: 'Johnson'}}, 'Alan Johnson'); + }); }); describe('#each', function() {