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

function similiar array_chunk in volt template engine.

hi everyone, how to use function similiar array_chunk in volt template engine. thank you

Just add it to volt. Check docs for more.

edited Jun '18

Yeah, either add it to volt, or just use plain PHP - that's what I do sometimes:

{{ set myArray = ['red','orange','yellow','green','blue','indigo','purple'] }}

<?php $myNewArray = array_chunk($myArray,2); ?>

{% for chunk in myNewArray %}
//code here
{% endfor %}

Well filter can be better for this so you can do for example:

{% for chunk in myArray|chunk(2) %}
// code here
{% endfor %}

Of course first you need to add it.

thank you all...



1.9k

$Compiler = $volt->getCompiler(); $Compiler->addFunction('isArray', 'is_array'); $Compiler->addFunction("date", 'date'); $Compiler->addFunction("strtotime", 'strtotime'); $Compiler->addFunction("array_chunk", 'array_chunk');

{{ array_chunk(a, b )}}

I just think as filter it will be better.