Skip to content

Commit 25cc890

Browse files
committed
- fix preserve Parent Context configuration for partial context handling
fix #1173
1 parent 0829644 commit 25cc890

2 files changed

Lines changed: 507 additions & 1 deletion

File tree

handlebars/src/main/java/com/github/jknack/handlebars/Context.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,12 @@ public static Context newBlockParamContext(
727727
*/
728728
public static Context newPartialContext(
729729
final Context ctx, final String scope, final Map<String, Object> hash) {
730-
return new PartialCtx(ctx, ctx.get(scope), hash);
730+
var currentModel = ctx.model;
731+
var scopedModel = ctx.get(scope);
732+
// don't introduce a new scope, when there is no need
733+
var parent = currentModel == scopedModel ? ctx.parent : ctx;
734+
// make sure parent is never null
735+
return new PartialCtx(parent == null ? ctx : parent, scopedModel, hash);
731736
}
732737

733738
/**

0 commit comments

Comments
 (0)