I want to show a property that is in an array of objects.
When I try to show it in php it works. It is like this.
foreach($elements as $element){
echo 'Order ID ['.$element->getOrders()->getId().']</br>';
echo 'Show element ['.$element->getId().']</br>';
echo 'Name ['.$element->getName().']</br>';
echo 'Type ['.$element->getType().']</br>';
}
But I don't know how to do that in twig.
First I send this to twig...
return array(
'elements' => $elements,
);
and in twig I try to show like this...
<ul>
<li>OrderID // ElementId // Name // Type </li>
{% for element in elements %}
<li>{{ attribute(element, '???')}} // {{ attribute(element, 'id')}} // {{ attribute(element, 'name')}} // {{ attribute(element, 'type')}} </li>
{% endfor %}
</ul>
Then my problem is how to show this OrderID. What I need to do in attribute or other function to show this.
attribute(array, 'elementName')is used when theelementNameis dynamic, because you can't callarray.dynamicElementName.