In php template I have an object $obj, which has some attributes like $obj->attr_1, $obj->attr_2 etc.
How can I call them from Twig template in the for loop?
I tried like this:
{% for i in 1..3 %}
{% set new_attr = 'attr_' ~ i %}
{{obj.new_attr}}
{% endfor %}
or like this
{% for i in 1..3 %}
{% set new_attr = 'attr_' ~ i %}
{{obj[new_attr]}}
{% endfor %}
but it does not work.
Try using attribute function.