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(
    array(
        'k'=>'val1'
    ),
    array(
        'k'=>'val2'
    ),
));

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?



19.6k
Accepted
answer

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