gutocf/page-title

Page Title component for CakePHP 4

Installs: 2 907

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:cakephp-plugin

1.2.0 2024-02-01 21:25 UTC

This package is auto-updated.

Last update: 2024-10-31 00:22:47 UTC


README

Build Status Coverage Status Latest Stable Version Total Downloads License PHPStan Packagist Version

Requirements

  • PHP 8.1+
  • CakePHP 5.0+

Note: For using with PHP 8.0 and CakePHP 4.3+ check out version 1.1.1

Installation

Install the plugin with composer

composer require gutocf/page-title

Plugin load

bin/cake plugin load PageTitle

Component load

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).

Usage

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>