-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Twig 2.11 is a breaking change - and still it is a minor release #3090
Comments
Can you share a reproducer (using https://twigfiddle.com/ for instance) ? |
Here is a fiddle that works with Twig 2.10.0 but fails with Twig 2.11.0: It implements exactly what is in the doc:
|
Just ran into this. My use case that broke on 2.11 (dumbed down): {% block body_html -%}
{% import 'macros.twig' as macros %}
{% block header_wrap %}
{{ macros.spacer(16) }}
Header
{{ macros.spacer(32) }}
{% endblock %}
{% block footer_wrap %}
{{ macros.spacer(32) }}
Footer
{{ macros.spacer(16) }}
{% endblock %}
{%- endblock %} |
I've just had an issue with this, too: {# macros.html.twig #}
{% macro foo %} ... {% endmacro %} {# base.html.twig #}
{% import 'macros.html.twig' as m %} {# page.html.twig #}
{% extends 'base.html.twig' %}
{% import _self as m %}
{{ m.foo }} fails with Twig 2.11.3 complainig about Macro "foo" is not defined in template "page.html.twig". |
@althaus your own case was never meant to work, as |
@stof, his example (reworked to add a block that he probably forgot to paste here) works with Twig 2.10: Not with Twig 2.11. That it was never meant to work is debatable. |
@ericmorand Yes, I tried to reduce our acutal code to show the problen. Thanks for creating the working fiddle! @stof: Don't know if this was meant to work, but it worked for roughly the last 5 years. |
@ericmorand the doc for macros are saying:
And there is another note explaining that a bit later in the doc (and this note was already there at least in Twig 2.9, so it is not something added to describe the changes done in 2.11):
|
I understood the issue reported by @althaus. He relied on a side-effect of the internal implementation of macros, where the |
@stof, thanks for the clarification with the doc. About the issue itself, it raises the same kind of debate that #3091 raised: if the implementation is faulty - and pre 2.11 macro support was faulty, shouldn't the existing project relying on this faulty implementation be considered as rightful? This is what you wrote for #3091:
That's exactly what is happening there with @althaus - and many others - project: it cares about the implementation, not the doc. What makes this situation different from #3091 ? |
@stof We started with Twig 1.15.0... so dunno how clear the doc has been at that time. ;-) So I've basically have to check all our templates and verify that they are properly importing any macros from any parent on their own? So a template is a black box regarding the resolving of macros? That sounds like fun... :( |
Wanted to throw another use case in here that this change breaks, since it's a little different: Apparently macros can no longer be passed as arguments to functions/extensions. Simplified example of what I was doing previously:
This now results in I understand this may or may not have not been a supported use case (though that's not really clear to me -- this is access within the same block), but it was certainly unexpected from a minor, supposedly backwards-compatible, update. Unfortunately I can't simply roll back as others have been doing because I need to support PHP 7.4. |
* proof of concept of Twig 3 upgrade * some for if template fixes * potentially fix RenderTokenParser * comment out RenderTokenParser * clearCompiledTemplates() using unlinkRecursive() * macro imported in block and used in subblock is not valid twigphp/Twig#3090 * more template fixes * remove non existing clearTemplateCache() * add missing parameter to unlinkRecursive * Use custom MethodCallExpression to fix RenderTokenParser * increase minimum php version to 7.2.5 * submodule update * fix twig loop filter * updates expected UI files * fix twig loop filter * fix twig loop filter * fix neutral evolution check * fix macro usage * convert some conditions to filters * fix macro include * remove debug code as default logging is good enough * submodule updates Co-authored-by: sgiehl <stefan@matomo.org>
The documentation explictly says so:
https://twig.symfony.com/doc/2.x/tags/macro.html#macros-scoping
A template written pre-2.11 is not guaranteed to render to the same result - or even compile successfully - using 2.11. This is a breaking change.
The text was updated successfully, but these errors were encountered: