We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

setTitle, prependTitle, appendTitle

class IndexController extends Phalcon\Mvc\Controller
{
    public function initialize()
    {
        \Phalcon\Tag::appendTitle(' - domain.com');
    }

    public function indexAction()
    {
        \Phalcon\Tag::setTitle('Homepage');
    }
}

In effect in index.phtml <?php echo Tag::getTitle() ?>

display only Homepage as a title.

Better could be if appendTitle,setTitle,prependTitle use internal indexed array for holding, and Tag::getTtitle() display sorted concatented this internal array.



98.9k

You can get the expected result by changing the order in which you set the parts of the title:

class IndexController extends Phalcon\Mvc\Controller
{
    public function initialize()
    {
        \Phalcon\Tag::setTitle(' - domain.com');
    }

    public function indexAction()
    {
        \Phalcon\Tag::prependTitle('Homepage');
    }
}

Yes i did it, but I think that if possible better could be indexed title parts, than manage it in head ;) I have no problem with this solution which exist, but I think that it could be improved for clarity.

Hi, If possible please add alternative method to setup title. There are situations where setting up title have to be build from recursive structure. For example, when you writing e-commerce website, main application task is to browse categories. It is very good practice to put product name - category name - subcategory name - subcategory name - website name using setTtitle, prependTitle, appendTitle could be exchange with something other build in framework. Of course it could be done myself, but i think that it could be build in framework, as Title exist in everywebsite. As I proposed solution could be indexed array, at the end concatented before display in view.