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.twig file.
{% 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
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
helper.twigfile.Expected behaviour
Output string.
Actual behaviour
Error: Call to a member function hasMacro() on null.
When called within the same file, it works fine
PHP version
8.2.20
Twig version
3.19