Skip to content

Instantly share code, notes, and snippets.

@Nyholm
Last active November 30, 2017 19:58
Show Gist options
  • Save Nyholm/4c2a960531d5d81c062b to your computer and use it in GitHub Desktop.
Save Nyholm/4c2a960531d5d81c062b to your computer and use it in GitHub Desktop.
Display flash messages in Symfony2
{# 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