From c3cbaa25a48d1a0c52ead31bfab28cb803cace1f Mon Sep 17 00:00:00 2001 From: kpdecker Date: Mon, 3 Aug 2015 17:27:38 -0500 Subject: Fix partial handling with different context --- lib/handlebars/runtime.js | 2 +- spec/partials.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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}} '; -- cgit v1.1