using variable in layout file

Hello.

I’m trying to use a variable in a layout file, but it seems it’s not available there.

in a controller:


$this->render($id, array('reader' => 'test'));

in a layout file:


<?php echo $reader; ?>

  • always empty

Please help.

Thank you.

Are you sure you use the correct view-file? What is $id set to?

Normally it should work the way you did.

The framework renders the view to a variable $output, then renders the layout file, passing $output to be rendered in the layouts content block.

You can declare $reader in the controller and access it with $this->reader.

/Tommy

Of course you’re right. Mixed it up with renderPartial :confused:

Thanks guys, this works excellent.

Hi! I had a similar problem because I had to put a banner in the layout… and the banner had to be different in the home page. I solved the problem in this way:




if (($this->id=='site')&&($this->action->id=='index')){

// Here the HOME banner

} else {

// Here the other banners

}

It’s obviously more clean and elegant that using a new variable!