Using the authentication extension

Dot-twigrenderer extends Twig with functions that use functionality from laminas/laminas-authentication to check if the user is authenticated and to get the authenticated identity object respectively.

public function hasIdentity(): bool;

public function getIdentity(): ?IdentityInterface;

Example usage

{% if hasIdentity() %}

    Welcome, {% getIdentity().username %}!

{% endif %}