Skip to content

Commit

Permalink
Add with block parameter support
Browse files Browse the repository at this point in the history
Fixes #1042
  • Loading branch information
kpdecker committed Aug 1, 2015
1 parent 410141c commit 2a85106
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/handlebars/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions spec/builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 2a85106

Please sign in to comment.