Layout inside of another layout?

I have a basic layout (main.php) that holds everything and echo's $content. Depending on the action I may want to implement another layout into the $content section. Let's say something like this:



<div class="withSideMenu">





   <div class="left">


      ... here should go the contents of $content


   </div>





   <div class="right">


      <?php $this->widget('SideMenu'); ?>


   </div>





</div>


I tried with beginContent() but had no success. Anyone can help?

I had a similar problem: a "sublayout" for each controller was needed, maybe my solution can help you:

In the main layout I do this:



<html>


...


<?php echo $this->renderPartial('_layout',array('content' => $content)); ?>


...


</html>


In the view folder you have a folder for each controller. In each controller folder you have a file _layout.php where you put your "sublayout":



<div class="withSideMenu">


   <div class="left">


      <?php echo $content; ?>


   </div>


   <div class="right">


      <?php $this->widget('SideMenu'); ?>


   </div>


</div>


For a more flexible solution you could introduce a new member variable in your controllers: public $sublayout = 'sublayout1';

In your main layout you could then do this:



<html>


...


<?php echo $this->renderPartial('/layouts/'.$this->sublayout,array('content' => $content)); ?>


...


</html>


Whenever you need to use a different sublayout, you then just set it in your action ($this->sublayout = 'sublayout2'). All your sublayouts would be in the layouts folder.

Thanks man that did the trick. I use the sublayout like this:

<?php echo (NULL === $this->subLayout) ? $content : $this->renderPartial('/layouts/' . $this->subLayout, array('content' => $content)); ?>

Yii rocks! ;D

You may also refer to this article: http://www.yiiframew…oc/cookbook/28/