Since the part to include the error was not answered here and I had to dig into the FOSUserBundle Code, let me also add to this post how to add the error messages to the loginPartial.html.twig form :
Have a look at the file /vendor/friendsofsymfony/user-bundle/Controller/SecurityController.php
This controller has an loginAction which builds the error variable. All you need to do in the controller you use to render the loginPartial twig is to add to this controller the following code.
$session = $request->getSession();
// get the error if any (works with forward and redirect -- see below)
if ($request->attributes->has(SecurityContextInterface::AUTHENTICATION_ERROR)) {
$error = $request->attributes->get(SecurityContextInterface::AUTHENTICATION_ERROR);
} elseif (null !== $session && $session->has(SecurityContextInterface::AUTHENTICATION_ERROR)) {
$error = $session->get(SecurityContextInterface::AUTHENTICATION_ERROR);
$session->remove(SecurityContextInterface::AUTHENTICATION_ERROR);
} else {
$error = null;
}
return $this->render('YourDemoBundle:Default:index.html.twig', ['error' => $error]);
In this case you are just using the same code in your controller to generate any login error messages i.e password incorrect etc.
Now in the twig which shows the form just add the following :
{% include 'YourDemoBundle:Security:loginPartial.html.twig' %}
And in the loginPartial.html.twig file put in this :
{% block fos_user_content %}
{% if error %}
<div>{{ error.messageKey|trans(error.messageData, 'security') }}</div>
{% endif %}`Let the rest of the form be as is....and then endblock ofcourse..{% endblock fos_user_content %}`
That should do it