We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Help with macro

I'm following the docs ( https://docs.phalcon.io/en/latest/reference/volt.html#macros ) to create a macro, but I just get a "undefined function" exception.

The macro (templates/admin.volt):

{%- macro admin() %}
    <h3>WORK DAMMIT</h3>
{%- endmacro %}

Then, in the template:

{% include 'templates/admin.volt' %}
{{ admin() }}


98.9k

Currently macros only work in the same template where they're defined



33.8k

But why? I see that the function is created in the same compiled template.



98.9k
Accepted
answer
edited Jan '15

Because a compiler is created per template and it keeps references to the macros created in the template itself.

Is it planned to support macros in included templates sometimes? In twig for example it works.