Tag Archives: placeholder

Zend_Layout : using placeholders

Supposing that you’re familiar with Zend_Layout and why and where you should use it, here’s a little tutorial how to use placeholders.

If there’s a layout file called main.phtml where beside the part of:

<?php echo $this->layout()->content; ?>

there’s a need for a placeholder.

The placeholder is the place in your layout file, in this case in main.phtml, where you’d like to inject a part of your view script.

In a standard way you’ve some script file like index.phtml of the index controller. In Zend as you may know this is the default view of the default controller, and in that controller contains the simple code like this:

$this->_helper->layout()->title = 'browser title';

and than you can be sure this browser title can appear in the layout file with adding something really similar to the line above.

Just add this:

<title><?php echo $this->layout()->title; ?></title>

And now that’s enough to setup a variable in a Zend controller and to call that variable in the layout script.