4

I want to print alt or title field image file in node twig template Drupal 8. I tried use {{ node.field_images.entity }} to debug get value title or alt but in class \Drupal\file\Entity\File not function get those ! I saw {{node.field_images.entity.fileuri}} in link

So how to used {{node.field_images.entity}} to get value alt or title file images ?

Thanks !

12

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 }}
2

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 }}

protected by kiamlaluno Jul 18 at 23:00

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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