Engine23

Using Zend Layout as a stand alone component

Using Zend_Layout as a Standalone Component

As a standalone component, Zend_Layout does not offer nearly as many features or as much convenience as when used with the MVC. However, it still has two chief benefits:

  • Scoping of layout variables.

  • Isolation of layout view script from other view scripts.

When used as a standalone component, simply instantiate the layout object, use the various accessors to set state, set variables as object properties, and render the layout:

  1. $layout = new Zend_Layout();
  2.  
  3. // Set a layout script path:
  4. $layout->setLayoutPath('/path/to/layouts');
  5.  
  6. // set some variables:
  7. $layout->content = $content;
  8. $layout->nav     = $nav;
  9.  
  10. // choose a different layout script:
  11. $layout->setLayout('foo');
  12.  
  13. // render final layout
  14. echo $layout->render();

Share: