You are here

status-messages.html.twig in Drupal 10

Default theme implementation for status messages.

Displays status, error, and warning messages, grouped by type.

An invisible heading identifies the messages for assistive technology. Sighted users see a colored box. See http://www.w3.org/TR/WCAG-TECHS/H69.html for info.

Add an ARIA label to the contentinfo area so that assistive technology user agents will better describe this landmark.

Available variables:

  • message_list: List of messages to be displayed, grouped by type.
  • status_headings: List of all status types.
  • attributes: HTML attributes for the element, including:
    • class: HTML classes.

File

core/themes/bartik/templates/status-messages.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Default theme implementation for status messages.
  5. *
  6. * Displays status, error, and warning messages, grouped by type.
  7. *
  8. * An invisible heading identifies the messages for assistive technology.
  9. * Sighted users see a colored box. See http://www.w3.org/TR/WCAG-TECHS/H69.html
  10. * for info.
  11. *
  12. * Add an ARIA label to the contentinfo area so that assistive technology
  13. * user agents will better describe this landmark.
  14. *
  15. * Available variables:
  16. * - message_list: List of messages to be displayed, grouped by type.
  17. * - status_headings: List of all status types.
  18. * - attributes: HTML attributes for the element, including:
  19. * - class: HTML classes.
  20. */
  21. #}
  22. <div data-drupal-messages>
  23. {% block messages %}
  24. {% if message_list is not empty %}
  25. {{ attach_library('bartik/messages') }}
  26. <div class="messages__wrapper layout-container">
  27. {% for type, messages in message_list %}
  28. {%
  29. set classes = [
  30. 'messages',
  31. 'messages--' ~ type,
  32. ]
  33. %}
  34. <div role="contentinfo" aria-label="{{ status_headings[type] }}"{{ attributes.addClass(classes)|without('role', 'aria-label') }}>
  35. {% if type == 'error' %}
  36. <div role="alert">
  37. {% endif %}
  38. {% if status_headings[type] %}
  39. <h2 class="visually-hidden">{{ status_headings[type] }}</h2>
  40. {% endif %}
  41. {% if messages|length > 1 %}
  42. <ul class="messages__list">
  43. {% for message in messages %}
  44. <li class="messages__item">{{ message }}</li>
  45. {% endfor %}
  46. </ul>
  47. {% else %}
  48. {{ messages|first }}
  49. {% endif %}
  50. {% if type == 'error' %}
  51. </div>
  52. {% endif %}
  53. </div>
  54. {# Remove type specific classes. #}
  55. {% set attributes = attributes.removeClass(classes) %}
  56. {% endfor %}
  57. </div>
  58. {% endif %}
  59. {% endblock messages %}
  60. </div>