All Projects → rephluX → laravel-pagetitle

rephluX / laravel-pagetitle

Licence: MIT license
Laravel package for managing page titles in blade views

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to laravel-pagetitle

Blogetc
Easily add a full Laravel blog (with built in admin panel and public views) to your laravel project with this simple package.
Stars: ✭ 198 (+942.11%)
Mutual labels:  blade, laravel-5-package
Pretty Routes
Pretty routes for Laravel
Stars: ✭ 549 (+2789.47%)
Mutual labels:  blade, laravel-5-package
baserepo
Base repository
Stars: ✭ 71 (+273.68%)
Mutual labels:  laravel-5-package
laravel-zxcvbn
Implementation of the zxcvbn project by @dropbox for Laravel.
Stars: ✭ 24 (+26.32%)
Mutual labels:  laravel-5-package
collage
Generate Image Collage with PHP and Laravel
Stars: ✭ 70 (+268.42%)
Mutual labels:  laravel-5-package
magic-box
A magical implementation of Laravel's Eloquent models as injectable, masked resource repositories.
Stars: ✭ 46 (+142.11%)
Mutual labels:  laravel-5-package
laravel-storyblok
Make Laravel and Storyblok work together beautifully.
Stars: ✭ 45 (+136.84%)
Mutual labels:  laravel-5-package
kirby-blade
Enable Blade for Kirby 3
Stars: ✭ 14 (-26.32%)
Mutual labels:  blade
laravel5-api
A modular controller for exposing Laravel 5 Eloquent models as a REST API
Stars: ✭ 13 (-31.58%)
Mutual labels:  laravel-5-package
content-management-system
Content management system for laravel developers'. It's easy to install and run.
Stars: ✭ 16 (-15.79%)
Mutual labels:  laravel-5-package
mail-template
💌 This package is a easy to use mail template collection for Laravel 5.x.
Stars: ✭ 18 (-5.26%)
Mutual labels:  laravel-5-package
laravel-email-exceptions
Email Exceptions package for Laravel 5.x
Stars: ✭ 33 (+73.68%)
Mutual labels:  laravel-5-package
querydumper
Laravel package to dump all running queries on the page.
Stars: ✭ 24 (+26.32%)
Mutual labels:  laravel-5-package
laravel-browsershot
Browsershot wrapper for Laravel 5
Stars: ✭ 108 (+468.42%)
Mutual labels:  laravel-5-package
laravel-decorator
Easily decorate your method calls with laravel-decorator package
Stars: ✭ 125 (+557.89%)
Mutual labels:  laravel-5-package
laravel-firebase
Laravel FCM (Firebase Cloud Messaging) Notification Channel
Stars: ✭ 25 (+31.58%)
Mutual labels:  laravel-5-package
laravel-vue-component
A Blade directive to ease up Vue workflow for Laravel projects
Stars: ✭ 19 (+0%)
Mutual labels:  laravel-5-package
laravel-geometry
SPINEN's Laravel wrapper over geoPHP
Stars: ✭ 36 (+89.47%)
Mutual labels:  laravel-5-package
laravel-assetcachebuster
Laravel 5 package that prefixes asset urls with a unique hash which will allow invalidation of asset files cached by the browser.
Stars: ✭ 33 (+73.68%)
Mutual labels:  laravel-5-package
maker
Laravel 5.4 maker
Stars: ✭ 18 (-5.26%)
Mutual labels:  laravel-5-package

Manage the Page Title in Blade views

Build Status Latest Stable Version Scrutinizer Code Quality License

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

Begin by installing this package through Composer:

composer require rephlux/pagetitle

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' => [
    '...',
    Rephlux\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' => Rephlux\PageTitle\Facades\PageTitle::class,
 ]

In Laravel 5.5, service providers and aliases are automatically registered. If you're using Laravel 5.5, you can skip these steps.

Version 2.0

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

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

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

<head>
    <meta charset="UTF-8">
    <title>{{ pagetitle()->get() }}</title>
    ...
</head>

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

<head>
    <meta charset="UTF-8">
    <title>{{ pagetitle()->get('reverse') }}</title>
    ...
</head>

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

<head>
    <meta charset="UTF-8">
    <title>{{ pagetitle()->get('downward') }}</title>
    ...
</head>

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="Rephlux\PageTitle\PageTitleServiceProvider"

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

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Page name
    |--------------------------------------------------------------------------
    |
    | Type your page name for your website.
    | This will be used when there are more titles to concatenate with.
    |
    */
    'page_name' => '',

    /*
    |--------------------------------------------------------------------------
    | Default title when empty
    |--------------------------------------------------------------------------
    |
    | This will be used when therer is no other title.
    | Mainly used for the home page of your website.
    |
    */
    'default_title_when_empty' => '',

    /*
    |--------------------------------------------------------------------------
    | Delimiter
    |--------------------------------------------------------------------------
    |
    | Titles will be concatenated using this delimiter.
    |
    */
    'delimiter' => ' :: ',
];

page_name

If you want you can enter your page name to this key if you want to append/prepend the name to your concatenated page title.

default_title_when_empty

This text will be used when there is are no page title parts in the collection.

delimiter

When you want to use a delimeter just update this key and add the string you want to use as an delimeter.

Change the configuration values

Each of the configuration parameters can be changed on the page title object instance with the correspondig setter methods:

  • setDelimeter(delimeter)
  • setPageName(pageName)
  • setDefault(default)

Example usage:

public function index()
{
    pagetitle('My Blog Post')->setPageName('My Blog')->setDelimeter(' / ');

    return view('hello');
}

To retrieve the current configuration values use the corresponding getter methods on the page title object instance:

  • getDelimeter()
  • getPageName()
  • getDefault()

License

View the license for this repo.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].