By mherchel on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
10.1.x
Introduced in version:
10.1.0
Issue links:
Description:
The new |add_class and |set_attribute Twig filters allow for setting CSS classes or attributes on field render arrays. This mitigates the need for modifying field templates or preprocessing just to add a CSS class.
Examples
{{ content.field_tags|add_class('my-class') }}adds themy-classCSS class to the field template forfield_tags.{{ content.field_tags|set_attribute('aria-hidden', 'true') }}adds thearia-hidden="true"attribute and value to the field template forfield_tags.
Impacts:
Themers
Comments
Maybe is not "|add_class and
Maybe is not "|add_class and |add_suggestion" but "|add_class and |set_attribute" ?
Good catch. Fixed!
Good catch. Fixed!
Premium component based Drupal themes
Am I misunderstanding what
Am I misunderstanding what this is supposed to do? I am trying to use this filter on a link field like this:
{{ content.field_card_link|add_class('btn') }}
And the resulting link element does not have any classes. This is on Drupal 10.2.0.
The wrapper will have the
The wrapper will have the class, not the a tag itself.
Drupal development and themeing, Galway, Ireland