Closed TLG-Gildas closed 3 months ago
Redefining a deferred block that is not the first deferred block of the parent template removes other blocks from rendering.
Here is a test to reproduce the issue :
--TEST-- Failed parents override --TEMPLATE-- {% extends "level1.twig" %} {% block overrided deferred %}{{ parent() }}:level2({{data|join(', ')}}){% endblock %} {% do data.append('lazy2') %} --TEMPLATE(level1.twig)-- {% block bar '[bar]' %} {% block foo deferred %}[foo]{% endblock %} {% block baz '[baz]' %} {% block overrided deferred %}[overrided]{% endblock %} {% block zoo '[zoo]' %} {% do data.append('lazy1') %} --DATA-- return [] --EXPECT-- [bar][foo][baz][overrided]:level2(lazy2, lazy1)[zoo]
This test currently produces this output : [baz][foo][zoo]
[baz][foo][zoo]
This test deliberately adds intermediate blocks to clearly see the abnormal behavior.
Here is a minimal version to reproduce the issue :
--TEST-- Failed parents override simple --TEMPLATE-- {% extends "level1.twig" %} {% block overrided deferred %}{{ parent() }}:level2{% endblock %} --TEMPLATE(level1.twig)-- {% block foo deferred %}[foo]{% endblock %} {% block overrided deferred %}[overrided]{% endblock %} --DATA-- return [] --EXPECT-- [foo][overrided]:level2
This test currently produces : [foo]
[foo]
In both cases, if we swap the foo and overrided blocks in level1.twig, then the expected rendering is correct.
--TEST-- Passed parents override --TEMPLATE-- {% extends "level1.twig" %} {% block overrided deferred %}{{ parent() }}:level2({{data|join(', ')}}){% endblock %} {% do data.append('lazy2') %} --TEMPLATE(level1.twig)-- {% block bar '[bar]' %} {% block overrided deferred %}[overrided]{% endblock %} {% block baz '[baz]' %} {% block foo deferred %}[foo]{% endblock %} {% block zoo '[zoo]' %} {% do data.append('lazy1') %} --DATA-- return [] --EXPECT-- [bar][overrided]:level2(lazy2, lazy1)[baz][foo][zoo]
--TEST-- Passed parents override simple --TEMPLATE-- {% extends "level1.twig" %} {% block overrided deferred %}{{ parent() }}:level2{% endblock %} --TEMPLATE(level1.twig)-- {% block overrided deferred %}[overrided]{% endblock %} {% block foo deferred %}[foo]{% endblock %} --DATA-- return [] --EXPECT-- [overrided]:level2[foo]
For my part, I have not yet managed to find the cause of the bug. You will undoubtedly be more efficient.
Hey @TLG-Gildas , thanks for reporting and investigating the issue! I believe it should be fixed by #19.
thanks for the work, unfortunately this doesn't fix the problem, I made a comment in the PR
Redefining a deferred block that is not the first deferred block of the parent template removes other blocks from rendering.
Here is a test to reproduce the issue :
This test currently produces this output :
[baz][foo][zoo]
This test deliberately adds intermediate blocks to clearly see the abnormal behavior.
Here is a minimal version to reproduce the issue :
This test currently produces :
[foo]
In both cases, if we swap the foo and overrided blocks in level1.twig, then the expected rendering is correct.
For my part, I have not yet managed to find the cause of the bug. You will undoubtedly be more efficient.