- Issue created by @agelospanagiotakis
- πΊπΈUnited States rlhawk Seattle, Washington, United States
Since you are adding classes directly to the image render array, rather than its parent image field, you don't need the Twig filter provided by this module. Something like this should work:
{% for key, image in content.field_image|filter((value, key) => not (key starts with '#')) %} <div class="splide__slide"> <div class="w-full px-4 text-center pb-3"> <a href="#" target="_blank"> {% set imageclasses = ["grayscale" ,"mx-auto" ,"opacity-80" ,"hover:opacity-100" ,"max-w-full" ,"h-auto"] %} {{ image|merge({'#item_attributes': {class: imageclasses}}) }} </a> </div> </div> {% endfor %}
Thank you, snippet from #2 is working and just saved me some headache while trying to add classes on the rendering of the first item of a multi value image field.
{{ content.field_pictures.0|merge({'#item_attributes': {class: ['rounded-3', 'mb-3']}}) }}
Thank you for sharing this.
- Status changed to Fixed
13 days ago 11:25pm 2 November 2024