File tree 1 file changed +20
-12
lines changed
1 file changed +20
-12
lines changed Original file line number Diff line number Diff line change 5
5
A common practice to better distinguish between templates and fragments is to
6
6
prefix fragments with an underscore. That's why this template is called
7
7
'_flash_messages.html.twig' instead of 'flash_messages.html.twig'
8
+
9
+ We check if we have session before reading flashes as it otherwise triggers session start:
10
+ https://symfony.com/doc/current/session/avoid_session_start.html
11
+
12
+ TIP: With FOSHttpCache you can also adapt this to make it cache safe:
13
+ https://foshttpcachebundle.readthedocs.io/en/latest/features/helpers/flash-message.html
8
14
#}
9
15
10
- <div class =" messages" >
11
- {% for type , messages in app .flashes %}
12
- {% for message in messages %}
13
- {# Bootstrap alert, see http://getbootstrap.com/components/#alerts #}
14
- <div class =" alert alert-dismissible alert-{{ type }} fade in" role =" alert" >
15
- <button type =" button" class =" close" data-dismiss =" alert" aria-label =" Close" >
16
- <span aria-hidden =" true" >× </span >
17
- </button >
16
+ {% if app .request .hasPreviousSession %}
17
+ <div class =" messages" >
18
+ {% for type , messages in app .flashes %}
19
+ {% for message in messages %}
20
+ {# Bootstrap alert, see http://getbootstrap.com/components/#alerts #}
21
+ <div class =" alert alert-dismissible alert-{{ type }} fade in" role =" alert" >
22
+ <button type =" button" class =" close" data-dismiss =" alert" aria-label =" Close" >
23
+ <span aria-hidden =" true" >× </span >
24
+ </button >
18
25
19
- {{ message | trans }}
20
- </div >
26
+ {{ message | trans }}
27
+ </div >
28
+ {% endfor %}
21
29
{% endfor %}
22
- {% endfor %}
23
- </ div >
30
+ </ div >
31
+ {% endif %}
You can’t perform that action at this time.
0 commit comments