In my layout (Twig), i'd like to retrieve a value from a Middleware authentication.
If i put, in templates.global.pĥp:
'twig' => [
'globals' => [
// Variables to pass to all twig templates
'auth' => (new \Zend\Authentication\AuthenticationService())->hasIdentity(),
],
],
And in layout default.html.twig
{% if auth %}
Connect
{% else %}
Not connect
{% endif %}
This code works, but, is it a good method ?
Thank you :)