From 2362ac8cbeeffb98322faa0adae1ea94f64a12a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20R?= Date: Wed, 26 Sep 2018 15:43:01 +0200 Subject: [PATCH] Fix session starting issue in symfony-demo on flash messages Use of flash messages triggers session start, which as of last year triggers Symfony to mark response as private. Fix the issue by checking if there is a session first as adviced on: https://symfony.com/doc/current/session/avoid_session_start.html --- templates/default/_flash_messages.html.twig | 32 +++++++++++++-------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/templates/default/_flash_messages.html.twig b/templates/default/_flash_messages.html.twig index 7b078e62f..8d859f52e 100644 --- a/templates/default/_flash_messages.html.twig +++ b/templates/default/_flash_messages.html.twig @@ -5,19 +5,27 @@ A common practice to better distinguish between templates and fragments is to prefix fragments with an underscore. That's why this template is called '_flash_messages.html.twig' instead of 'flash_messages.html.twig' + + We check if we have session before reading flashes as it otherwise triggers session start: + https://symfony.com/doc/current/session/avoid_session_start.html + + TIP: With FOSHttpCache you can also adapt this to make it cache safe: + https://foshttpcachebundle.readthedocs.io/en/latest/features/helpers/flash-message.html #} -
- {% for type, messages in app.flashes %} - {% for message in messages %} - {# Bootstrap alert, see http://getbootstrap.com/components/#alerts #} - +
+{% endif %}