Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
I have a node with an image field.
On my node--name.html.twig I can print my image with {{ content.field_image }}.
But I want to add a class on my <img>
. Is there a way to do it in my template ?
I think so, because when I print the keys on my content.field_image.0 I have #image_style and #item_attributes.
Thanks.
Comments
Comment #2
KeeneganComment #3
idebr CreditAttribution: idebr at ezCompany commentedHi Keenegan,
Have a look at the contributed module Twig Field Value: https://www.drupal.org/project/twig_field_value
It allows the following code:
Comment #4
KeeneganThanks for the module !
I was just wondering if I could do this without any contrib module, but after researching I think it's not possible.
Comment #5
joelpittetIt's possible without contrib, instead of
content
look at the values innode
IIRC, then you have access to the field without the render information.