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

Pass data (array) to template problem.

I have next code in my controller:

$this->view->setVar('someAr', array(

in my .volt file (general layout):

{{ someAr[0]['k'] }},{{ someAr[1]['k'] }}

returns val1,val2 (as expected).

But this code returns nothing:

{% for itemt in someAr %}
    {{ itemt.k }}
{% endfor %}

What I'm doing wrong?


As you said, you use an Array, not an Object. The syntax where using/iterating/etc in an array is the one that returns OK your arrays values: the syntax that fails for you is for using/iterating/etc in an object (you know, $object->variable. Also I think you call his functions the same way).

    {{ item['k'] }}