Search code examples
phpzend-frameworkbootstrappingpage-title

Zend: How to add webpage title in all my views?


For now I have to add title in all my views separately like this:

<head>
       <title>TestProject - Home</title>
</head>

and

<head>
       <title>TestProject - Dashboard</title>
</head>

Now if I want to change TestProject part of title then I have to change it in all my views. How can I mentioned this in BootStrap.php and add it in all views? And whenever I have to change this, I will change this in one place.


Solution

  • In Bootstrap.php

    protected function _initViewHelpers() {
        $view = new Zend_View();
        $view->headTitle('Main Title')->setSeparator(' - ');
    }
    

    In any view/.phtml

    <?php 
        $this->headTitle()->prepend('Page Title');
        echo $this->headTitle();
    ?>