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 loop & user defined functioin

Is it not possible to use a user defined function in a loop?



213
Accepted
answer

I am not sure if I understand you properly, but in my opinion it is possible:

// Add your function to the volt compiler

$compiler->addFunction('square', function($arg) { return $arg . ' * ' . $arg; });

// call it in the view:

{% for i in 1..10 %} {{ i }} - {{ square(i) }}<br/> {% endfor %}



33.8k

I tried something as Jacek says some days ago, but I always getted some error related with params.

But yeah, he is right about the syntax.