Drupal - How to print alt or title field image in twig node template?

The alt and title properties are stored in the image field, not in the file entity. You can access them by replacing the entity property with alt or title:

{{ node.field_image.title }}
{{ node.field_image.alt }}

In the field template (field.html.twig) this will work.

{% for item in items %}
    {{ item.content['#item'].alt }}
{% endfor %}

In node.html.twig or paragraph.html.twig, this will work.

{{ content.field_image['#items'].alt }}

Tags:

Theming

8