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

Loop array items via properties in Volt

Documentation says (https://docs.phalcon.io/en/latest/reference/volt.html#variables)

Variables¶
Variables may have attributes which can be accessed using the syntax: foo.bar. If you are passing arrays, you CAN access using the square bracket syntax: foo[‘bar’]

{{ post.title }}
{{ post['title'] }}

Does CAN mean MUST for Volt? Or should I set up something to make it working? (Twig handle everything in dot notation and I miss it here)

PHP - data
$menu = array(array('id' => 'test1'), array('id' => 'test2'));
$this->view->setVar('menu', $menu);
...
Volt
{% for index, item in menu %}
    {{ index }} {{  item['id'] }} vs {{ item.id }}
{%  endfor %}

{{ item.id }} ends up with Notice: Trying to get property of non-object

edited Oct '14

You are correct.

Arrays:

{{ item['id'] }} // translates to item['id']

objects

{{ item.id }} // translates to $item->id

We just need to correct the documentation in that area. If you don't mind can you either open an issue or send a pull request for this in the docs repo?

Thanks!

It would be great if arrays and objects can be accessed the same way with dot:

{{ post.title }}