Last active
November 30, 2017 19:58
-
-
Save Nyholm/4c2a960531d5d81c062b to your computer and use it in GitHub Desktop.
Display flash messages in Symfony2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# Check if we got a session without creating one #} | |
{% if app.request.hasPreviousSession %} | |
{# Check if we got some flash messages #} | |
{% if app.session.flashbag.peekAll()|length > 0 %} | |
<div id="flash"> | |
{# Loop all types of flash messages #} | |
{% for type, flashMessages in app.session.flashbag.all() %} | |
{# For all flash messages with this type #} | |
{% for idx, flashMessage in flashMessages %} | |
<div class="flash-item flash-type-{{ type }}"> | |
{{ flashMessage|trans|trim }} | |
</div> | |
{% endfor %} | |
{% endfor %} | |
</div> | |
{% endif %} | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment