I am using the FOSUserBundle in Symfony 3.4. Everything is working correctly. I am overriding the FOSUserBundle templates with my own. The way I am checking if the user failed to login because of an incorrect password or email is this way:
login.html.twig
{% trans_default_domain 'FOSUserBundle' %}
...Some html nothing fancy
{% if error %}
<div>{{ error.messageKey|trans(error.messageData, 'security') }}</div>
{% endif %}
....Rest of file content
</div>
This runs no problem. The user of course is redirected to the index page after failure handled via my security file.
However, I tried using the if statement above in the index.html.twig, it thinks it is undefined. I want to use it so I can for example, when the user gets redirected to index page for my customized message to appear. Is there a for the "error" variable in that twig file to be made global to all twig files when it gets set?