Variable issues

Hello, How can i pass variable around in laminas-mvc?
I tried to use the normal viewmodel approach but I am not able to get the variable in my layout, but if i set the variable via layout approach, i could get it in the layout but not get it in other view files.

Please look at the view helper “Layout” which can be used in each view script. The helper offers the possibility to set variables for the layout script.
The “Placeholder” helper is another option.

It all depends on what you have in mind.

https://docs.laminas.dev/laminas-view/helpers/layout/
https://docs.laminas.dev/laminas-view/helpers/placeholder/