I must use a Twig variable as a property for another Twig variable.
In a for loop, I get the properties of a specific entity and want to use those properties to get the property-content for an entity variable in an other for loop.
Some code to make this clear:
{% for entity in entities %} {{entity.foo}}, {{entity.bar}}<br /> {% for property in specialdynamicproperties %} {{entity.property}} <!-- property has the content foobar for example, I want to use it as the property accessor for entity --> {% endfor %} {% endfor %}
Thanks.
The attribute function is what you are looking for.
Edit:
{{ attribute(object, method) }} {{ attribute(object, method, arguments) }} {{ attribute(array, item) }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With