> $this->view->layout()->#variablename# = value;

This didn't work for me from an action controller.

Here is what I ended up using a mixture of. I don't know if these are the
best ways but I found them useful.

You can use this in your view template:

$this->headTitle('New Zend Framework Project');
Or 
$this->headTitle($this->controllerSetVarHere);

Then in your layout template.

echo $this->headTitle();

The only downfall is that you have to have a view template. Or at least I
have not found a direct way to set them on the layout template.

You can also set template vars directly to the layout template from your
action controller, like this :

// assign var directly to layout template 
// ( - requires small adjustment to zend/layout.php -
http://framework.zend.com/issues/browse/ZF-4895)
Zend_Layout::getMvcInstance()->assign('varname', 'varvalue');

Then its simply a $this->varname in your layout template.

Some other useful layout functions :

-- disableLayout:

For when you don't want any layout template but would want the view rendered
only.

// disable layout
Zend_Layout::getMvcInstance()->disableLayout();

-- setLayout:

Change the layout template, I used this when I have special layouts that are
not the default layout.

// change layout file
Zend_Layout::getMvcInstance()->setLayout('404_base_page');

-- setLayoutPath:

Used this to make a subdirectory file system for the layout templates. But
now I use less templates so not using anymore but still useful.

// change layout path
Zend_Layout::getMvcInstance()->setLayoutPath('new/path/to/layout);

Hope those help.

I'm using all these, except the setLayoutPath, on
http://e-edition.tbnweekly.com

Hope that helps some.

Terre
 

Reply via email to