field--text.html.twig

Same filename in this branch
  1. 10 core/profiles/demo_umami/themes/umami/templates/classy/field/field--text.html.twig
  2. 10 core/themes/olivero/templates/field/field--text.html.twig
  3. 10 core/themes/claro/templates/classy/field/field--text.html.twig
Same filename in other branches
  1. 9 core/profiles/demo_umami/themes/umami/templates/classy/field/field--text.html.twig
  2. 9 core/themes/olivero/templates/field/field--text.html.twig
  3. 9 core/themes/seven/templates/classy/field/field--text.html.twig
  4. 9 core/themes/claro/templates/classy/field/field--text.html.twig
  5. 9 core/themes/bartik/templates/classy/field/field--text.html.twig
  6. 9 core/themes/starterkit_theme/templates/field/field--text.html.twig
  7. 9 core/themes/classy/templates/field/field--text.html.twig
  8. 8.9.x core/profiles/demo_umami/themes/umami/templates/classy/field/field--text.html.twig
  9. 8.9.x core/themes/seven/templates/classy/field/field--text.html.twig
  10. 8.9.x core/themes/claro/templates/classy/field/field--text.html.twig
  11. 8.9.x core/themes/bartik/templates/classy/field/field--text.html.twig
  12. 8.9.x core/themes/classy/templates/field/field--text.html.twig
  13. 11.x core/profiles/demo_umami/themes/umami/templates/classy/field/field--text.html.twig
  14. 11.x core/themes/olivero/templates/field/field--text.html.twig
  15. 11.x core/themes/claro/templates/classy/field/field--text.html.twig
  16. 11.x core/themes/starterkit_theme/templates/field/field--text.html.twig

Default theme implementation 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.

A 'text-formatted' class is added to assist with default styling of base elements such as paragraphs and lists that may not have classes assigned to them. This allows user entered content to have default styling without interfering with the styles of other UI components such as system generated lists or other dynamic content.

See also

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

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

File

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

View source
  1. {% extends "field.html.twig" %}
  2. {#
  3. /**
  4. * @file
  5. * Default theme implementation 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. * A 'text-formatted' class is added to assist with default styling of base
  18. * elements such as paragraphs and lists that may not have classes assigned to
  19. * them. This allows user entered content to have default styling without
  20. * interfering with the styles of other UI components such as system generated
  21. * lists or other dynamic content.
  22. *
  23. * @see https://www.drupal.org/node/2539860
  24. *
  25. * @ingroup themeable
  26. */
  27. #}
  28. {% set attributes = attributes.addClass('clearfix', 'text-formatted') %}

Related topics


Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.