Calling methods on array element

Hi all,

i don't know if it is a bug but i'm not able to call any method over an object stored in array: The following code compiles in a wrong PHP code wich won't work: {{ myarray['myobject'].my_method() }}

The result of the compilation is like: <?php echo ($myarray['myobject'])->my_method(); ?>

As you can see the extra parentheses surrounding $myarray['myobject'] will result in a PHP Fatal Error.

As a workaround i've the need every time to use a temp var like this {% set myobj = myarray['myobject'] %} {{ myobj.my_method() }}

I suppose VOLT should not add those parentheses so far. Thanks

It can be a bug, file a ticket at github. Normally you just pass all objects into your view or Do if they are services, and then call methods on'em. No need for arrays.


Thanks for the replay but i suppose that arrays are often used to display several objects of the same type. Even single objects are needed to be passed to view and no problem with that.


If they are so if the same type, then just iterate through them. Each time you enter a new iteration, you'll get an instance you can call methods directly on.

See for-loops in Volt documentation.