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.

Volt loop & user defined functioin

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


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


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.