Dry Design With Views

Yii supports DRY (Don’t Repeate Yourself) design.

I find myself repeating the same code for views over and over. Only a couple of things change, such as the page title, the model being edited… and I thought those things might be parameters to a "view template".

This way, if for example, I want to change the title size from "h1" to "h3", I could do it once on the view template and all the views that use it will update the title size.

Is there any ‘yii-official’ approach to abstract the views code?

Thank you.

Hi Tomsea

you could set as many variables you want in components/controller

for example

class Controller extends CController {

public $mylayoutval1;


Then set it in your view

$this->mylayoutval1="this is a custom layout text"

and in your theme/layout file echo $this->mylayoutval1 in the way you want