multiple content place holder variables for layout

In a layout file, we a special content holder variable called $content, which basically gets decorated when we do a $this->render('index') in our controller.

What would the best way be to say add another content holder variable, say $side_content and also have that be decorated from the result of another view, also determined in controller action.

Well, here is one approach:

   

     

        $content = $this->renderPartial('index', array('what' => 'what', 'side' => 'sidebar', 'settings' => $settings, 'site_settings' => $site_settings),true, false);

        $side_content = $this->renderPartial('site_sidebar', array(), true, false);

        $layout=Yii::app()->layout;     

      $layoutFile=$this->getLayoutFile($layout);

        $this->renderFile($layoutFile, array('content' => $content, 'side_content' => $side_content));

        $this->processOutput($output);

Hmm…not very pretty but maybe only solution?

unless the $this->render() can pass additional "$content" variables that can be injected into the Layout.

You can use "clip" feature. Check API for CBaseController and CClipWidget.

Here is example:

// in the controller

$this->beginClip('sideContent');

$this->renderPartial('module_sidebar', array());

$this->endClip();

$this->render('index', array());

// in the layout

<?php echo $this->clips['sideContent'] ?>

So which approach do you think is better? Both works, is one more efficient then other?

       

Efficiency-wise, they are similar. Using clips is more convenient.