Layout with multiple content sections

What do you think of a small modification of CController.render method to accept array of views instead of single view. If array is passed, than the method would renderPartial each view using the same data and would pass variables $content1, $content2, etc. into layout.

For example.



<tr><td>LEFT</td><td><?php echo $content1; ?></td><td>RIGHT</td></tr> 

<tr><td>LEFT</td><td><?php echo $content2; ?></td><td>RIGHT</td></tr> 


Action in controller:

$this->render(array('navigator', 'grid'));


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


		$self = $this;

		$renderPartial = function($v) use ($self, $data) {

			return $self->renderPartial($v,$data,true);


		$renderedViews = array_map($renderPartial, is_array($view) ? $view : array($view));




			if (count($renderedViews) == 1)


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




				$indices = array_keys($renderedViews);

				$keys = array_map(function($index) {return "content".($index+1);}, $indices);

				$params = array_combine($keys, array_values($renderedViews));

				$output = $this->renderFile($layoutFile, $params, true);





			$output = array_reduce($renderedViews, function($a, $x) {return $a.$x;});




			return $output;


			echo $output;



use widgets


See if this suits you:

Yes it’s a good way. But you have the main content in the middle and the portlets/widgets on the right and on the left. If you want to update the widget in ajax independently, there is no way… or I have miss something?

It should work to put the widget in a view file and use renderPartial() for initial load and ajax update. (So far, I’ve just used this method for main content.)


Ah ok, nice way :) I’ll try it… But with this method you will update the entire widget, not a specified view in the widget, a detail I think.

Partials can be nested within other partials.

Take a closer look at the blog demo. The post content and comments are rendered in two partials nested within an outer partial. Read the section called Nested Caching in the User Guide for a explanation of caching the outer view partials and the inner view partials independently(partials are called view fragments in the docs as in fragments of the overall view).

If you think of the outer partials as layout regions, you could have outer partials for embedding your left and right columns as well as your content. Inner partials could be rendered in each one of these and cached independently. You could also have other regions (e.g., a header partial with embedded partials for artwork, banners, menus, breadcrumbs, etc.