Symfony - Setting Flash and Checking in TWIG
In Controller
$this->get('session')->getFlashBag()->set('error', 'Does Not Exist');
or
$this->get('session')->getFlashBag()->add('error', 'Does Not Exist');
In Twig
{% for flashMessage in app.session.flashbag.get('error') %}
{{ flashMessage }}
{% endfor %}
FYI: Doc
In Controller :
$this->get('session')->getFlashBag()->add('error', "User does not exists.");
In View :
{% for type, messages in app.session.flashbag.all() %}
{% for message in messages %}
{% if type == 'error' %}
{{ message }}
{% endif %}
{# Or even with css class rendering:
<div class="flash-{{type}}">{{message}}</div>
#}
{% endfor %}
{% endfor %}