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 %}

Thanks.



33.6k
Accepted
answer

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

Is this branch stable? Should I upgrade?

Thanks.

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

edited Jun '15

Great.

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