You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
while updating Twig to version 3 we encountered a problem with template extensions when passing an array of templates to the extends tag.
The problem occurs, when you extend a parent template, which contains two nested blocks and a child template which overrides the outer block and calls the parent() function (i.e. to wrap the contents of the parents outer block), while also overriding the inner block.
If the child extends the parent directly, passing only a string to extends, it woks as expected: The content of the childs inner block is used.
If the child extends the same parent but passes it via an array (because there might be other templates that could be extended instead), the output will contain the parents default value for the inner block instead.
Here is a minimal example that demonstrates the problem: https://twigfiddle.com/itkl51
Notice how the output shows inner default instead of the expected inner actual.
If the extends tag is changed from {% extends ["parent.twig"] %} to {% extends "parent.twig" %}, the output will change to the expected inner actual.
Here's the full example code as reference, in case the above link dies at some point.
This PR was merged into the 3.x branch.
Discussion
----------
Add some tests
Closes#3691
The bug described in #3691 has been fixed via #3999.
This PR adds tests to prove it works now and to avoid future regressions.
Commits
-------
85c2ba5 Add some tests
Hello,
while updating Twig to version 3 we encountered a problem with template extensions when passing an array of templates to the
extends
tag.The problem occurs, when you extend a parent template, which contains two nested blocks and a child template which overrides the outer block and calls the
parent()
function (i.e. to wrap the contents of the parents outer block), while also overriding the inner block.If the child extends the parent directly, passing only a string to
extends
, it woks as expected: The content of the childs inner block is used.If the child extends the same parent but passes it via an array (because there might be other templates that could be extended instead), the output will contain the parents default value for the inner block instead.
Here is a minimal example that demonstrates the problem: https://twigfiddle.com/itkl51
Notice how the output shows
inner default
instead of the expectedinner actual
.If the
extends
tag is changed from{% extends ["parent.twig"] %}
to{% extends "parent.twig" %}
, the output will change to the expectedinner actual
.Here's the full example code as reference, in case the above link dies at some point.
The text was updated successfully, but these errors were encountered: