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

VOLT: macro is already defined

Hi all,

i'm using $this->view->render to render some VOLT templates and store the result in a file later. All works fine but i'm getting in trouble with macros now because VOLT causes an exception if i call multiple times render on the template which contains the macro definition. Off course i can move the declaration in a separate template file but i'm looking for a way to avoid this.

I've even tried with a new view instance with

$this->di->get('view')->render

but even in this case Phalcon complains about double declaration. Can i render a template independently from others with macros available just during that render/file and than discarded?

Thanks very much Gianks



20.4k
Accepted
answer

Partially resolved with includes/partials. Passing variables acts like a macro/function call and even if i need more than one template files this way i can render just the "parent" template multiple times without any more code in the controller. I guess this approach leads to poor performances if compared to compiled macros, so i cannot consider this a definitive solution.

Suggestions are welcome!