- PHP 8.1+
- CakePHP 5.0+
Note: For using with PHP 8.0 and CakePHP 4.3+ check out version 1.1.1
Install the plugin with composer
composer require gutocf/page-title
bin/cake plugin load PageTitle
Load the component in App\Controller\AppController:
$this->loadComponent('Gutocf/PageTitle.PageTitle', [
'default' => 'MyApp Name', //Default page title - optional, default = null
'var' => 'var_name_for_views', //Var name to set at view - optional, default = title
'separator' => ' :: ', //Titles separator - optional, default = ' / '
'reverseOrder' => true, //Display titles in reverse order of inclusion - optional, default = true
]);
You need to load the component in controllers or application's AppController (recomended).
To add titles to your page, simply call PageTitle::add method with one or more parameters:
$this->PageTitle->add('Articles', 'Add');
In Controller.beforeRender event, the component will set a variable with $config['var'] name for use in the views and templates, in this example Add :: Articles :: MyApp Name (Or MyApp Name :: Articles :: Add if reverseOrder option is false). You can set the page title by including this code in the template file src/templates/default.php
<head>
<title><?= $this->get('var_name_for_views') ?></title>
</head>