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.

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