Specific path to view template with condition

I have in my component 3 users roles: admin, client, guest.
I want that template is displayed depending on user role:
so if user have ‘admin’ role, than template view path will following:


and same for other roles!

I tried to attach render event and getting ViewModel for changing template path but when i called


returned empty string

What should i do for customize path to view template by some variable - identity role in this case?

In the laminas-view documentation you will find an example of working with a listener:


In your case, add the authentication service (Laminas\Authentication\AuthenticationServiceInterface) to the listener via constructor and then you must set the template for the correct view model:

/** @var ViewModel|null $contentViewModel */
$contentViewModel = (array_filter(
        static fn(ViewModel $child) => $child->captureTo() === 'content'
    ))[0] ?? null;

if ($contentViewModel) {