summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2015-08-03 17:27:38 -0500
committerkpdecker <kpdecker@gmail.com>2015-08-03 17:27:38 -0500
commitc3cbaa25a48d1a0c52ead31bfab28cb803cace1f (patch)
treeb521d0718db51786053df866dde14a43d6699bc9
parent9b1f9c7e4434d99f0dd013db4370b1b59c3754b7 (diff)
downloadhandlebars.js-c3cbaa25a48d1a0c52ead31bfab28cb803cace1f.zip
handlebars.js-c3cbaa25a48d1a0c52ead31bfab28cb803cace1f.tar.gz
handlebars.js-c3cbaa25a48d1a0c52ead31bfab28cb803cace1f.tar.bz2
Fix partial handling with different context
-rw-r--r--lib/handlebars/runtime.js2
-rw-r--r--spec/partials.js6
2 files changed, 7 insertions, 1 deletions
diff --git a/lib/handlebars/runtime.js b/lib/handlebars/runtime.js
index 9dae284..744e6eb 100644
--- a/lib/handlebars/runtime.js
+++ b/lib/handlebars/runtime.js
@@ -136,7 +136,7 @@ export function template(templateSpec, env) {
blockParams = templateSpec.useBlockParams ? [] : undefined;
if (templateSpec.useDepths) {
if (options.depths) {
- depths = context !== options.depths[0] ? [context].concat(depths) : options.depths;
+ depths = context !== options.depths[0] ? [context].concat(options.depths) : options.depths;
} else {
depths = [context];
}
diff --git a/spec/partials.js b/spec/partials.js
index b2fc9e0..a9cd3dd 100644
--- a/spec/partials.js
+++ b/spec/partials.js
@@ -238,6 +238,12 @@ describe('partials', function() {
var hash = {root: 'yes', dudes: [{name: 'Yehuda', url: 'http://yehuda'}, {name: 'Alan', url: 'http://alan'}]};
shouldCompileToWithPartials(string, [hash, {}, {dude: partial}, true], true, 'Dudes: Yehuda (http://yehuda) yes Alan (http://alan) yes ');
});
+ it('partials can access parents with custom context', function() {
+ var string = 'Dudes: {{#dudes}}{{> dude "test"}}{{/dudes}}';
+ var partial = '{{name}} ({{url}}) {{root}} ';
+ var hash = {root: 'yes', dudes: [{name: 'Yehuda', url: 'http://yehuda'}, {name: 'Alan', url: 'http://alan'}]};
+ shouldCompileToWithPartials(string, [hash, {}, {dude: partial}, true], true, 'Dudes: Yehuda (http://yehuda) yes Alan (http://alan) yes ');
+ });
it('partials can access parents without data', function() {
var string = 'Dudes: {{#dudes}}{{> dude}}{{/dudes}}';
var partial = '{{name}} ({{url}}) {{root}} ';