In most cases, the above configuration and layout script (with modifications) will get you what you need. However, some other functionality exists you will likely use sooner or later. In all of the following examples, you may use one of the methods listed above for retrieving the layout object.
-
Setting layout variables.
Zend_Layoutkeeps its own registry of layout-specific view variables that you can access; the$contentkey noted in the initial layout script sample is one such example. You can assign and retrieve these using normal property access, or via theassign()method.// Setting content: $layout->somekey = "foo" // Echoing that same content: echo $layout->somekey; // 'foo' // Using the assign() method: $layout->assign('someotherkey', 'bar'); // Access to assign()'d variables remains the same: echo $layout->someotherkey; // 'bar' -
disableLayout(). Occasionally, you may want to disable layouts; for example, when answering an Ajax request, or providing a RESTful representation of a resource. In these cases, you can call thedisableLayout()method on your layout object.$layout->disableLayout();
The opposite of this method is, of course,
enableLayout(), which can be called at any time to re-enable layouts for the requested action. -
Selecting an alternate layout: If you have multiple layouts for your site or application, you can select the layout to use at any time by simply calling the
setLayout()method. Call it by specifying the name of the layout script without the file suffix.// Use the layout script "alternate.phtml": $layout->setLayout('alternate');The layout script should reside in the
$layoutPathdirectory specified in your configuration.Zend_Layoutwill then use this new layout when rendering.




