Is it possible to render module layout inside app layout?

Just wondering if anyone knows if you can render a module layout inside application layout within the $content variable? Basically I want to have widgets on every module page.

so… application layout >> module layout >> module view

I did something like the following to accomplish this. It allows me to render a "decorator" around the content of the template before rendering the main layout file.




abstract class MyController extends CController

{

	/**

	 * The name of the decorator template

	 * @var string

	 */

	private $decorator = 'main';


	/**

	 * Override the render functionality to add in our admin controller stuff

	 *

	 * @param string $view

	 * @param array $data

	 * @param boolean $return

	 * @return mixed

	 */

	public function render($view,$data=null,$return=false)

	{

		// Render the child template, this is the inner display

		$output=$this->renderPartial($view,$data,true);


		// Render our decorator

		if (($decoratorFile = $this->getLayoutFile($this->decorator)) !== false)

			$output = $this->renderFile($decoratorFile, array('content' => $output), true);


		// Render the main template

		if (($layoutFile = $this->getLayoutFile($this->layout)) !== false)

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


		// Process

		$output = $this->processOutput($output);


		// Finalize

		if ($return)

			return $output;

		else

			echo $output;

	}

}



Then you just make your controller extend MyController (eg: class SiteController extends MyController { }) and it will plug in seamlessly.

If you want to have a different decorator for a given controller, then just override the value of $decorator in the child class.

Is that what you are looking for?

yep, that’s exactly what I was looking for.

Thanks!