You are here

status-messages.html.twig in Zircon Profile 8.0

Theme override 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.
  • display: (optional) May have a value of 'status' or 'error' when only displaying messages of that specific type.
  • attributes: HTML attributes for the element, including:
    • class: HTML classes.

See also

template_preprocess_status_messages()

File

core/themes/classy/templates/misc/status-messages.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Theme override 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. * - display: (optional) May have a value of 'status' or 'error' when only
  19. * displaying messages of that specific type.
  20. * - attributes: HTML attributes for the element, including:
  21. * - class: HTML classes.
  22. *
  23. * @see template_preprocess_status_messages()
  24. */
  25. #}
  26. {{ attach_library('classy/messages') }}
  27. {% block messages %}
  28. {% for type, messages in message_list %}
  29. {%
  30. set classes = [
  31. 'messages',
  32. 'messages--' ~ type,
  33. ]
  34. %}
  35. <div role="contentinfo" aria-label="{{ status_headings[type] }}"{{ attributes.addClass(classes)|without('role', 'aria-label') }}>
  36. {% if type == 'error' %}
  37. <div role="alert">
  38. {% endif %}
  39. {% if status_headings[type] %}
  40. <h2 class="visually-hidden">{{ status_headings[type] }}</h2>
  41. {% endif %}
  42. {% if messages|length > 1 %}
  43. <ul class="messages__list">
  44. {% for message in messages %}
  45. <li class="messages__item">{{ message }}</li>
  46. {% endfor %}
  47. </ul>
  48. {% else %}
  49. {{ messages|first }}
  50. {% endif %}
  51. {% if type == 'error' %}
  52. </div>
  53. {% endif %}
  54. </div>
  55. {# Remove type specific classes. #}
  56. {{ attributes.removeClass(classes) }}
  57. {% endfor %}
  58. {% endblock messages %}