Friday, June 01, 2012

How to Set dynamic page titles in YII

One way to specify the page title in YII, you can go to controller/action, and set it this way.
public function actionIndex() {
     $this->pageTitle = "Put page title here";
     $this->render('index');
}

In the header template or layout template, you can do the following:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="language" content="en" />   
    <title><?php echo CHtml::encode($this->pageTitle); ?></title>
</head>
Or in the view page, you can specify the pageTitle. 
$this->setPageTitle('Put page title here');

No comments: