From f7494850e2ffe71b8d6e64297a0d1c49d37fd68f Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Sun, 28 Jun 2026 23:59:58 +0200 Subject: [PATCH] Fix regression caused in 5.8.1. Fixes #1192 --- changelog/1192.md | 1 + src/Runtime/InheritanceRuntime.php | 8 ++------ src/Template.php | 6 +++++- 3 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 changelog/1192.md diff --git a/changelog/1192.md b/changelog/1192.md new file mode 100644 index 00000000..89ce92d5 --- /dev/null +++ b/changelog/1192.md @@ -0,0 +1 @@ +- fixed a regression from #1189 where a child template's block override no longer applied to a template {include}d by the parent [#1192](https://github.com/smarty-php/smarty/issues/1192) diff --git a/src/Runtime/InheritanceRuntime.php b/src/Runtime/InheritanceRuntime.php index 60cf7980..74ea8544 100644 --- a/src/Runtime/InheritanceRuntime.php +++ b/src/Runtime/InheritanceRuntime.php @@ -69,12 +69,8 @@ class InheritanceRuntime { * @param array $blockNames outer level block name */ public function init(Template $tpl, $initChild, $blockNames = []) { - // if called while executing parent template it must be a sub-template with new inheritance root. - // A new root is started either by a child template ($initChild) or by a sub-template included - // outside of any block rendering (empty source stack); the latter must not inherit the leftover - // block overrides of a previously completed inheritance tree (see issue #1189). - if (($initChild || empty($this->sourceStack)) && $this->state === 3 - && (strpos($tpl->template_resource, 'extendsall') === false)) { + // if called while executing parent template it must be a sub-template with new inheritance root + if ($initChild && $this->state === 3 && (strpos($tpl->template_resource, 'extendsall') === false)) { $tpl->setInheritance(clone $tpl->getSmarty()->getRuntime('Inheritance')); $tpl->getInheritance()->init($tpl, $initChild, $blockNames); return; diff --git a/src/Template.php b/src/Template.php index 242fb238..5a8363a5 100644 --- a/src/Template.php +++ b/src/Template.php @@ -260,7 +260,11 @@ class Template extends TemplateBase { $tpl = $this->smarty->doCreateTemplate($template_name, $cache_id, $compile_id, $this, $caching, $cache_lifetime); - $tpl->inheritance = $this->getInheritance(); // re-use the same Inheritance object inside the inheritance tree + // Re-use the same Inheritance object only inside an active inheritance tree, i.e. when this + // (including) template already has one. A template outside any inheritance tree has no + // Inheritance object (null); sub-templates it {include}s must then start with their own, so an + // {include}d template that uses {block}/{extends} creates a fresh root via getInheritance(). + $tpl->inheritance = $this->inheritance; if ($scope) { $tpl->defaultScope = $scope;