{# layouts/partials/flashbag.html.twig #}
{% import _self as flashbag %}
<div id="flash-message-container">
{% for message in app.flashes('error') %}
{{ flashbag.renderFlashMessage( message, [ 'alert-danger' ] ) }}
{% endfor %}
{% for message in app.flashes('warning') %}
{{ flashbag.renderFlashMessage( message, [ 'alert-warning' ] ) }}
{% endfor %}
{% for message in app.flashes('info') %}
{{ flashbag.renderFlashMessage( message, [ 'alert-info' ] ) }}
{% endfor %}
{% for message in app.flashes('success') %}
{{ flashbag.renderFlashMessage( message, [ 'alert-success' ] ) }}
{% endfor %}
{# read and display all flash messages #}
{% for label, messages in app.flashes %}
{% for message in messages %}
{{ flashbag.renderFlashMessage( message, [ 'alert-dark', label ] ) }}
{% endfor %}
{% endfor %}
</div>
{% macro renderFlashMessage( message, classes ) %}
{% if message is iterable %}
{% if 'classes' in message|keys %}
{% set classes = classes|merge( message.classes ) %}
{% endif %}
{% set message = message[0] %}
{% endif %}
<div class="alert alert-dismissible fade show {{ classes|join(' ') }}" role="alert">
<div>{{ message|raw }}</div>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
{% endmacro %}