Skip to content

Commit

Permalink
bug #4336 Fix template name in error for an unknown dynamic extends c…
Browse files Browse the repository at this point in the history
…alled from an include (fabpot)

This PR was merged into the 3.x branch.

Discussion
----------

Fix template name in error for an unknown dynamic extends called from an include

Closes #3265

The code was introduced in #1529, but removing it nowadays does not break any existing test.

Review ignoring whitespace.

Commits
-------

4824f2a Fix template name in error for an unknown dynamic extends called from an include
  • Loading branch information
fabpot committed Sep 26, 2024
2 parents 57147e7 + 4824f2a commit f4b17ce
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
23 changes: 8 additions & 15 deletions src/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,16 @@ public function getParent(array $context): self|TemplateWrapper|false
return $this->parent;
}

try {
if (!$parent = $this->doGetParent($context)) {
return false;
}

if ($parent instanceof self || $parent instanceof TemplateWrapper) {
return $this->parents[$parent->getSourceContext()->getName()] = $parent;
}
if (!$parent = $this->doGetParent($context)) {
return false;
}

if (!isset($this->parents[$parent])) {
$this->parents[$parent] = $this->loadTemplate($parent);
}
} catch (LoaderError $e) {
$e->setSourceContext(null);
$e->guess();
if ($parent instanceof self || $parent instanceof TemplateWrapper) {
return $this->parents[$parent->getSourceContext()->getName()] = $parent;
}

throw $e;
if (!isset($this->parents[$parent])) {
$this->parents[$parent] = $this->loadTemplate($parent);
}

return $this->parents[$parent];
Expand Down
14 changes: 14 additions & 0 deletions tests/Fixtures/tags/inheritance/dynamic_parent_from_include.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
"extends" tag
--TEMPLATE--
{{ include('included.twig') }}

--TEMPLATE(included.twig)--



{% extends dynamic %}
--DATA--
return ['dynamic' => 'unknown.twig']
--EXCEPTION--
Twig\Error\LoaderError: Template "unknown.twig" is not defined in "included.twig" at line 5.

0 comments on commit f4b17ce

Please sign in to comment.