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

Access view variables or services in volt's Macros

Hi all,

Is there any way that view variables & services can be accessed through the macro in volt? For example I want to access router service in macro:

{%- macro getClass(key) %}
    {% return router.getActionName() == key ? "active" : "" %}
{%- endmacro %}



In Phalcon 2.0.4 you can do that (2.0.x branch)

Is this branch stable? Should I upgrade?


In Phalcon 2.0.4 you can do that (2.0.x branch)

edited Jun '15


I'm waiting for merging :)

This do the magic in 2.0.4:

         * Bind the closure to the $this object allowing to call services
        let code .= macroName . " = \\Closure::bind(" . macroName . ", $this); ?>";

Thanks @andrez