Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Help with macro

I'm following the docs ( http://docs.phalconphp.com/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() }}


83.4k

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



18.6k

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



83.4k
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.