How does Zend link $this->layout()->content with scripts/index/index.phtml?
I think I'm failing to understand the basics of how the pages are supposed to stick together. I've looked at the quick start on the zend site but it's far too simplistic.
So as Tomáš Fejfar explained that's how the $this->layout()->content
works. Yet what is interesting is that 'content' is not just a variable in the layout. In fact, 'content' is a key in a View placeholder called 'Zend_Layout'. For this reason, the following snippets are equivalent to echo $this->layout()->content
in your layout.phtml:
$placeHolder = Zend_View_Helper_Placeholder_Registry::getRegistry()->getContainer('Zend_Layout');
echo $placeHolder['content'];
// or
echo $this->placeholder('Zend_Layout');
// or
echo $this->placeholder('Zend_Layout')->content;
This can be very useful. What I mean is that you can define some places in your layout.phtml that will be display values of your custom keys from 'Zend_Layout' placeholder. For instance, imagine that you would like to have a layout.phtml and you want to be able to modify text in your footer. You could do this by defining layout.phtml which will contain the following in the footer:
<div id="footer">
<?php echo $this->layout()->myFooterText; ?>
</div>
You could setup a default value for this footer in e.g. your Bootstrap.php. However, if you wanted you could modify this text in your actions as follows;
$this->view->placeholder('Zend_Layout')->myFooterText = 'Some text only for this action';
That's it what I wanted to add. Off course one could think of other scenerios, because $this->view->placeholder('Zend_Layout')
is an instance of Zend_View_Helper_Placeholder_Container
so you could do other things with Zend_Layout placeholder.
EDIT: Key 'content' is a default name. You can change it to something else using setContentKey method of Zend_Layout, e.g.:
protected function _initSetNewLayoutContentKey() {
$layout = $this->bootstrap('layout')->getResource('layout');
// instead of 'content' use 'viewoutput'
$layout->setContentKey('viewoutput');
}
With this change, in your layout.phtml you would use echo $this->layout()->viewoutput;
instead of echo $this->layout()->content;
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With