Using clips
One of the Yii features you can use in your views is clips . The basic idea is that you can record some output and then reuse it later in a view. A good example would be defining additional content regions for your layout and filling them elsewhere.
Getting ready
Set up a new application using yiic webapp.
How to do it...
For our example, we need to define two regions in our layout:
beforeContentandfooter. Openprotected/views/layouts/main.phpand insert the following code line just before the content output(<?php echo $content; ?>):<?php if(!empty($this->clips['beforeContent'])) echo $this->clips['beforeContent']?>
Then, insert the following into
<div id="footer">:<?php if(!empty($this->clips['footer'])) echo $this->clips['footer']?>
That is it! Now, we need to fill these regions somehow. We will use a controller action for the
beforeContentregion. Openprotected/controllers/SiteController.phpand add the following code toactionIndex:$this...