You can write a custom twig extension with a function that uses PropertyAccess for symfony to get the value. An example implementation of an extension may be as follows:
<?php
use Symfony\Component\PropertyAccess\PropertyAccess;
class PropertyAccessorExtension extends \Twig_Extension
{
protected $accessor;
public function __construct()
{
$this->accessor = PropertyAccess::createPropertyAccessor();
}
public function getFunctions()
{
return array(
new \Twig_SimpleFunction('getAttribute', array($this, 'getAttribute'))
);
}
public function getAttribute($entity, $property) {
return $this->accessor->getValue($entity, $property);
}
public function getName()
{
return 'property_accessor_extension';
}
}
,
{% for entity in array %}
{{ getAttribute(entity, "child.child.prop1") }}
{% endfor %}
!