Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x

field--text.html.twig

Same filename in this branch
  1. 11.1.x core/profiles/demo_umami/themes/umami/templates/classy/field/field--text.html.twig
  2. 11.1.x core/themes/starterkit_theme/templates/field/field--text.html.twig
  3. 11.1.x core/themes/claro/templates/classy/field/field--text.html.twig

Theme override for a text field.

A 'clearfix' class is added, because 'text' fields have a 'format' property that allows a Text Format to be associated with the entered text, which then applies filtering on output. A common use case is to align images to the left or right, and without this 'clearfix' class, such aligned images may be rendered outside of the 'text' field formatter's boundaries, and hence overlap with other fields. By setting the 'clearfix' class on all 'text' fields, we prevent that.

See also

https://www.drupal.org/node/2358529

File

core/themes/olivero/templates/field/field--text.html.twig

View source
  1. {% extends "field.html.twig" %}
  2. {#
  3. /**
  4. * @file
  5. * Theme override for a text field.
  6. *
  7. * A 'clearfix' class is added, because 'text' fields have a 'format' property
  8. * that allows a Text Format to be associated with the entered text, which then
  9. * applies filtering on output. A common use case is to align images to the left
  10. * or right, and without this 'clearfix' class, such aligned images may be
  11. * rendered outside of the 'text' field formatter's boundaries, and hence
  12. * overlap with other fields. By setting the 'clearfix' class on all 'text'
  13. * fields, we prevent that.
  14. *
  15. * @see https://www.drupal.org/node/2358529
  16. *
  17. * @ingroup themeable
  18. */
  19. #}
  20. {% set attributes = attributes.addClass('clearfix') %}

Related topics

Theme system overview
Functions and templates for the user interface that themes can override.
RSS feed
Powered by Drupal