We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

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.

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'] }}