Layout for static pages

Hi folks,

I’m totally new to YII, so this question might be quite silly, but where do I change the default layout for static pages? I know that with dynamic pages I do it in controller’s action… Is there any method I have to overwrite for the static pages, so I can chose a different layout?

Any help highly appreciated,

Miro.

Since the view are executed before the layout you can simply add this to the view (assuming other_layout.php)




$this->layout = '//layouts/other_layout';



/Tommy

That’d be on a per-page basis.

You could do it in a per controller basis (and still affecting only static pages), using an exclusive controller for rendering static pages.

Hi there,

It’s an old thread but I came across this issue and want to help others who might have the same problem.

In order for the static pages to use the same layout that the dynamic ones are using, do this:

Edit SiteController.php and add the following code in the SiteController


class SiteController extends Controller

{

	/**

	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning

	 * using two-column layout. See 'protected/views/layouts/column2.php'.

	 */

	public $layout='//layouts/column2';



Where column2 refers to the column2.php file which is located inside the /themes/MyTheme/layouts/ directory.

I hope this helps :)

Yes it’s an old thread but it came up when I was searching for a solution to a problem.

I have a controller that deals with various profiles, these profiles were imported from another system, along the way I made notes for my client and I wanted a static view to allow the client to refer to this in case people got lost during the transition.

So I put this code in my ‘profile’ controller.


        	public function actions()

	{

		return array(

			// page action renders "static" pages stored under 'admin/views/profile/pages'

			// They can be accessed via: index.php?r=profile/page&view=FileName

			'page'=>array(

				'class'=>'CViewAction',

                            'layout'=>'//layouts/admin1col'

			),

		);

	}

And in the default view I put this CMenu array. Second entry is the link to the static view.

The view is called import_notes.php and placed in /views/profile/pages


$this->menu=array(

	array('label'=>'Catalog Main', 'url'=>array('SBCatalog/admin')),

	array('label'=>'Import Notes', 'url'=>array('profile/page','view'=>'import_notes')),

);



Might help someone along the way :)