0
{%
  set fields_array = [
    'field_address',
    'field_phone',
  ]
%}
{% for field in fields_array %}
  {{ node.field }}
{% endfor %}

How to concate dynamic value to node object?

  • You can concatenate like 'field_address_' ~ value, but maybe you are wanting array keys like {{ field.0.value}}? – Prestosaurus Mar 25 at 6:00
  • @Prestosaurus In that code, field is a string, so field.0.value would not give what the OP wants. – kiamlaluno Mar 25 at 8:57
1

To get a field with the field name stored in the variable field you can use the method get() on the node:

{{ node.get(field).value }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.