A plugin to automatically generate titles for web pages using routes from the HTTP request url.
This plugin will automatically generate a working title using values such as the request's controller
, action
, prefix
if there is one and the app name
if you provide one.
You can set our own format by configuring the Component when loading it in your application.
Plugin | Branch | Cake | PHP |
---|---|---|---|
2.x | main | 5.x | ^8.1 |
1.x | 1.x | 4.x | ^7.4 | ^8.0 |
format
- How the generated title should be formatted. See valid placeholders below.- Default format:
{{prefix} - }{{controller} - }{{action} - }{{displayField}}{ » {appName}}
- Example generated: Admin - Files Types - View - PDF » CakePHP application
- Default format:
appName
- Your application's name. Used as replacement for theappName
placeholder.ignoreIndex
- If true, and the requested action isindex
, then the action will not be placed in the titleshowDisplayFieldOnView
- If true, the display field value (e.g. the files type's name) will be placed in the title.
appName
- Will be replaced by the app's name, if you provide one in the component's configurationcontroller
- Will be replaced by the requested controlleraction
- Will be replaced by the requested actionprefix
- Will be replaced by the requested prefix, if there is one.displayField
- If your action stores an entity variable in the view, the component attempts to get the entity's display field value to display in the title- For example: If you have a table called Tools and the display field is the tool's name, it will place the tool's name in the title.
- The display field value is not fetched on its own from the database. It attempts to find a view var in which to get the value from.
- Please note that the entity variable must be named using cake's convention. A Tool entity variable must be
$tool
. A FilesType entity must be named$filesType
.
// On the top, with your other use statements
use Avolle\Title\Plugin as TitlePlugin;
/**
* Boostrap method. Load required plugins
*
* @return void
*/
public function bootstrap(): void
{
$this->addPlugin(TitlePlugin::class, ['autload' => true]);
}
/**
* Initialization hook method.
*
* @return void
* @throws \Exception
*/
public function initialize(): void
{
parent::initialize();
$this->loadComponent('Avolle/Title.Title', [
'appName' => 'Title App',
'format' => '{{prefix} - }{{controller} - }{{action} - }{{displayField}}{ » {appName}}',
'ignoreIndex' => false,
'showDisplayFieldOnView' => true,
]);
}
<head>
<title><?= $title; ?></title>
</head>