Iterate through multiple value content field in Twig template I need to take control over the rendering of a field_admin_tags field in a node.html.twig template.

This WORKS:


{{ content.field_admin_tags }} — Renders everything (label + all field values)
{{ content.field_admin_tags.0 }} — Renders only the first value in the field, and no label


PROBLEM: I have no control over the markup surrounding the tags, e.g. &lt;ul&gt;&lt;li&gt;...&lt;/li&gt;&lt;/ul&gt;.

So my idea was to iterate over the render array.

But that DOES NOT work:

{% for tag in content.field_admin_tags %}
  {{ tag }}
{% endfor %}


I get: Exception: Object of type Drupal\node\Entity\Node cannot be printed.

I think I'm iterating over the keys/values of the render array vs the items inside the field (if I print out an "X" in each loop, I get 20 X's while I only have two or three values in this field).

I'd like to iterate over content.field_admin_tags.0, content.field_admin_tags.1, etc.

Any idea how to fix this? Thanks.
Agree with 4k4 the field template is the best place, if you really want it in the entity template (e.g. node) you can do something like this:

{% for key, item in content.field_tags if key|first != '#' %}
  &lt;div class="item-{{ key + 1 }}"&gt;{{ item }}&lt;/div&gt;
{% endfor %}


But honestly I think it's a bit ugly, the field template is the right place.