In This Article

Layout

The Layout helper is used to get and set the template for the layout or to retrieving the root view model.

Basic Usage

Change the Layout Template

If you're running a zend-mvc application then the layout template is set in the configuration for the ViewManager.

To change the layout template within a view script, call:

$this->layout('layout/backend');

Or use the setTemplate method:

$this->layout()->setTemplate('layout/backend');

Set View Variable on Layout Model

The Layout helper can also retrieve the view model for the layout (root):

/** @var \Zend\View\Model\ViewModel $rootViewModel */
$rootViewModel = $this->layout();

This offers the possibility to set variables for the layout script.

Set a Single Variable

$this->layout()->setVariable('infoText', 'Some text for later');

Use in your layout script:

if (isset($infoText)) {
    echo $infoText;
}

Set a Set of Variables

$this->layout()->setVariables([
    'headerText' => '…',
    'footerText' => '…',
]);

More informations related to view models can be found in the quick start.

Found a mistake or want to contribute to the documentation? Edit this page on GitHub!