PHPackages                             atereshchuk/pagetitle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. atereshchuk/pagetitle

ActiveLibrary[Templating &amp; Views](/categories/templating)

atereshchuk/pagetitle
=====================

Manage page title in Laravel views

1.0.1(1y ago)010MITPHPPHP ^7.2|^8.0|^8.1|^8.2|^8.3

Since Jan 22Pushed 1y agoCompare

[ Source](https://github.com/AndriiTereshchuk/laravel-pagetitle)[ Packagist](https://packagist.org/packages/atereshchuk/pagetitle)[ Docs](https://github.com/AndriiTereshchuk/laravel-pagetitle)[ RSS](/packages/atereshchuk-pagetitle/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

Manage the Page Title in Blade views
====================================

[](#manage-the-page-title-in-blade-views)

Often, you'll find yourself in situations, where you want to have more to control how to set a page title for your different views. Although it is possible to yield your page title in a master view it can be a hassle to deal with the format like a delimeter usage or to append/prepend a default page title.

This package simplifies the process.

Installation
------------

[](#installation)

Begin by installing this package through Composer:

```
composer require atereshchuk/pagetitle
```

### Laravel Users

[](#laravel-users)

If you are a Laravel user, then there is a service provider that need to add to your `config/app.php` file.

```
'providers' => [
    '...',
    ATereshchuk\PageTitle\PageTitleServiceProvider::class,
];
```

This package also provides a facade, which you may also register in your `config/app.php` as well if you want to use the facade in your controllers and views:

```
 'aliases' => [
     '...'
     'PageTitle' => ATereshchuk\PageTitle\Facades\PageTitle::class,
 ]
```

> In Laravel 5.5, [service providers and aliases are automatically registered](https://laravel.com/docs/5.5/packages#package-discovery). If you're using Laravel 5.5, you can skip these steps.

Version 2.0
-----------

[](#version-20)

If you still use PHP 7.0 or 5.6 you need to use version 1.0 of this package. Version 2.0 and above is only compatible with PHP 7.1 or newer.

Version 2.0 of this package is also compatible with Laravel 5.5 and newer.

Useage
------

[](#useage)

To simple add a single page title, call the appropiate `add()` method with passing a string as a parameter:

```
public function index()
{
    \PageTitle::add('Welcome to our Homepage');

    return view('hello');
}
```

You can also make use of the global `pagetitle` helper function.

```
public function index()
{
    pagetitle('Welcome to our Homepage');

    return view('hello');
}
```

To add multiple page title parts at once just pass an array as a parameter.

```
public function index()
{
    pagetitle([
        'About us',
        'Profile'
    ]);

    return view('hello');
}
```

### Add the pagetitle to a blade view

[](#add-the-pagetitle-to-a-blade-view)

Now you can display the fully concatenated page title in your view. The best way is to use it in your master layout file.

```

    {{ pagetitle()->get() }}
    ...

```

To display the fully concatenated page title in reverse order just pass the `reverse` parameter.

```

    {{ pagetitle()->get('reverse') }}
    ...

```

The `downward` mode first concatenates all page title parts in reverse order and then appends the page name ( *if set in options* )

```

    {{ pagetitle()->get('downward') }}
    ...

```

### Defaults

[](#defaults)

If using Laravel, there are three configuration options that you'll need to worry about. First, publish the default configuration with the following command:

```
php artisan vendor:publish --provider="ATereshchuk\PageTitle\PageTitleServiceProvider"
```

This will add a new configuration file to: `config/pagetitle.php`.

```
