layout , rendering and passed variables ?

Hi

I noticed when executing an action I tried to pass a variable

but wanted to render this variable in the main.php main layout,

but this couldn’t be. the variable can only be used in the

file asked to be rendered in the Action.

my question is :

can I pass a variable from my any action to be used in the main layout file ?

Hi,

the answer is Yes, you can. In your layout controller instance is available as $this. So you could define new controller class public member variable, set its value in action and access it like $this->varName in you layout file.

Thanks MadAnd, That’s the trick.

so I guess you confirm that the scope of the variables prepared in a controller Render context cannot be accessed for the main layout for instance?

Yes I confirm that, also this is done "by design", because if some part of template is heavy depends on variables passed from controller - this should be part of some view, but not layout. Layout is supposed to be just decoration. Using widgets is best choice for layout-level data rendering.