0

In the node template, I print an image gallery. I need to add the alt text.

<div class="field--name-field_gallery">
  {{ content.field_gallery }}
  {{ content.field_gallery.alt_field }}
</div>

There are many images, which are printed, but the alt text is not printed.

How can I print it?

0

Print the image field in the node template like any other field:

{{ content.field_gallery }}

And then use a field twig to loop through multiple field items:

field--field-gallery.html.twig

 <div class="row expanded">
  {% for item in items %}
     {{ item.content }}
     {{ item.alt }}
    {% endfor %}
  </div>
  • I have not tried it yet, but I think it should work. Thank you – Evi Oct 23 '17 at 12:17
-1

You can something like this:

{{ node.field_image.title }}
{{ node.field_image.alt }}
  • It prints only first image alt text. – Evi Oct 23 '17 at 11:57

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.