-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[3.x] macros not working with null coalescing operator #4776
Copy link
Copy link
Closed
Description
Description
Twig macro variables don't work when imported from a separate file, and a fallback is provided using a null coalescing operator. However, macros defined within the same template are callable.
Steps to reproduce
- Create a macro in a
helper.twigfile.
{% macro foo(param) %}
{{ param }}
{% endmacro %}
- Call this macro in a different file.
{% from 'helper.twig' import foo %}
{{ foo('bar') ?? '' }}
Expected behaviour
Output string.
Actual behaviour
Error: Call to a member function hasMacro() on null.
When called within the same file, it works fine
{% macro foo(param) %}
{{ param }}
{% endmacro %}
{{ _self.foo('bar') ?? '' }}
{# Output: bar #}
PHP version
8.2.20
Twig version
3.19
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels