Best way to share the same user interface

I want to add the following to all of the Profile section.

What is the best (and enough optimized) way to share the following code?

Currently i’m using this directly in the Profile controller’s index view (profile/index)


<div style="width:150px">

<?php

$this->beginWidget('zii.widgets.CPortlet', array(

    'title' => 'Profile Options',

    'id' => 'ajaxPortlet',

));


$this->widget('zii.widgets.CMenu',array(

    'activateItems'=>true,

    'activateParents'=>true,

    'items'=>array(

        array('label'=>'Change Password', 'url'=>'/profile/password','active'=>Yii::app()->controller->action->id=='password')


    ),

));

?>

</div>

<?php

$this->endWidget();

place it in a layout file and at the top of your Profile controller state


public $layout='//layouts/newlayoutname'

This should be good enough

Thank you, this worked.

Another related question: In which overriden function should i set $layout to remove my shared bar and change it with something special for that function? (while still in profile controller but requiring full page width)

beforeAction? or is it too late?

It can be set in the action or even in the view template - layout will be rendered after the current action’s view.