Lucas Courot

Render all flash messages in Twig

Posted on by

The official Symfony2 doc explains how to render a notice message in Twig.

But sometimes you might want to render all flash messages without relying on their notices.

Here is how to do it:

{% for label, flashes in app.session.flashbag.all %}
    {% for flash in flashes %}
        <div class="alert alert-{{ label }}">
            {{ flash }}
        </div>
    {% endfor %}
{% endfor %}

Enjoy!

See the other articles published in Symfony .