summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2015-08-01 15:48:16 -0500
committerkpdecker <kpdecker@gmail.com>2015-08-01 15:48:28 -0500
commit2a851067b99c3932e471f5fc1a2d40dc25a084c4 (patch)
treee60d5e58b2daba3c912e5c2db4b13c159af0b268
parent410141c31e547694746f3ce9427d1dde30070777 (diff)
downloadhandlebars.js-2a851067b99c3932e471f5fc1a2d40dc25a084c4.zip
handlebars.js-2a851067b99c3932e471f5fc1a2d40dc25a084c4.tar.gz
handlebars.js-2a851067b99c3932e471f5fc1a2d40dc25a084c4.tar.bz2
Add with block parameter support
Fixes #1042
-rw-r--r--lib/handlebars/base.js9
-rw-r--r--spec/builtins.js4
2 files changed, 10 insertions, 3 deletions
diff --git a/lib/handlebars/base.js b/lib/handlebars/base.js
index a1847fc..c2f14eb 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 46d70ba..9598743 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() {