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">


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

    'title' => 'Profile Options',

    'id' => 'ajaxPortlet',






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







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.