Skip to content

Commit c3cbaa2

Browse files
committed
Fix partial handling with different context
1 parent 9b1f9c7 commit c3cbaa2

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/handlebars/runtime.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export function template(templateSpec, env) {
136136
blockParams = templateSpec.useBlockParams ? [] : undefined;
137137
if (templateSpec.useDepths) {
138138
if (options.depths) {
139-
depths = context !== options.depths[0] ? [context].concat(depths) : options.depths;
139+
depths = context !== options.depths[0] ? [context].concat(options.depths) : options.depths;
140140
} else {
141141
depths = [context];
142142
}

spec/partials.js

+6
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ describe('partials', function() {
238238
var hash = {root: 'yes', dudes: [{name: 'Yehuda', url: 'http://yehuda'}, {name: 'Alan', url: 'http://alan'}]};
239239
shouldCompileToWithPartials(string, [hash, {}, {dude: partial}, true], true, 'Dudes: Yehuda (http://yehuda) yes Alan (http://alan) yes ');
240240
});
241+
it('partials can access parents with custom context', function() {
242+
var string = 'Dudes: {{#dudes}}{{> dude "test"}}{{/dudes}}';
243+
var partial = '{{name}} ({{url}}) {{root}} ';
244+
var hash = {root: 'yes', dudes: [{name: 'Yehuda', url: 'http://yehuda'}, {name: 'Alan', url: 'http://alan'}]};
245+
shouldCompileToWithPartials(string, [hash, {}, {dude: partial}, true], true, 'Dudes: Yehuda (http://yehuda) yes Alan (http://alan) yes ');
246+
});
241247
it('partials can access parents without data', function() {
242248
var string = 'Dudes: {{#dudes}}{{> dude}}{{/dudes}}';
243249
var partial = '{{name}} ({{url}}) {{root}} ';

0 commit comments

Comments
 (0)