Fix regression caused in 5.8.1.

Fixes #1192
This commit is contained in:
Simon Wisselink
2026-06-28 23:59:58 +02:00
parent 17fae11a38
commit f7494850e2
3 changed files with 8 additions and 7 deletions
+1
View File
@@ -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)
+2 -6
View File
@@ -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;
+5 -1
View File
@@ -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;