You are here

status-messages.html.twig in Express 8

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.
  • 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

themes/contrib/bootstrap/templates/system/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. * - 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. * @ingroup templates
  24. *
  25. * @see template_preprocess_status_messages()
  26. */
  27. #}
  28. {%
  29. set status_heading = {
  30. 'status': 'Status message'|t,
  31. 'error': 'Error message'|t,
  32. 'warning': 'Warning message'|t,
  33. 'info': 'Informative message'|t,
  34. }
  35. %}
  36. {%
  37. set status_classes = {
  38. 'status': 'success',
  39. 'error': 'danger',
  40. 'warning': 'warning',
  41. 'info': 'info',
  42. }
  43. %}
  44. {% for type, messages in message_list %}
  45. {%
  46. set classes = [
  47. 'alert',
  48. 'alert-' ~ status_classes[type],
  49. 'alert-dismissible',
  50. ]
  51. %}
  52. <div{{ attributes.addClass(classes) }} role="alert">
  53. <a href="#" role="button" class="close" data-dismiss="alert" aria-label="{{ 'Close'|t }}"><span aria-hidden="true">&times;</span></a>
  54. {% if status_headings[type] %}
  55. <h4 class="sr-only">{{ status_headings[type] }}</h4>
  56. {% endif %}
  57. {% if messages|length > 1 %}
  58. <ul class="item-list item-list--messages">
  59. {% for message in messages %}
  60. <li class="item item--message">{{ message }}</li>
  61. {% endfor %}
  62. </ul>
  63. {% else %}
  64. {{ messages|first }}
  65. {% endif %}
  66. </div>
  67. {% endfor %}