kminek/laravel-title 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kminek/laravel-title

最新稳定版本:v3.0.0

Composer 安装命令:

composer require kminek/laravel-title

包简介

Probably the easiest way to add dynamic HTML title to Laravel app

README 文档

README

Probably the easiest way to add dynamic HTML title to Laravel app

Installation

Run the following command from your terminal:

composer require kminek/laravel-title

or add this to require section in your composer.json file:

"kminek/laravel-title": "^3.0"

then run composer update

Version compatibility

laravel/framework kminek/laravel-title
13.x 3.x
11.x / 12.x 1.x / 2.x

Usage

Modify your layout view (for example resources/views/layouts/app.blade.php):

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>{{ title() }}</title>
    </head>
    <body>
        <main>
            @yield('content')
        </main>
    </body>
</html>

Modify your controller action view (for example resources/views/auth/register.blade.php):

@extends('layouts.app')

@title('Register')

@section('content')

    <h1>
        Register
    </h1>

    ...

@endsection

Advanced usage

Change default separator (|):

<title>{{ title()->separator(' - ') }}</title>

Change default text (config('app.name')):

<title>{{ title()->default('AppName') }}</title>

Set a description which is displayed when no title is set inside controller action view:

<title>{{ title()->default('AppName')->description('This app will blow your mind!') }}</title>

You are not required to use @title() Blade directive, you can call library directly which opens more possibilities:

@extends('layouts.app')

@php(title()->append('Register')) {{-- append (same behaviour as Blade directive) --}}
@php(title()->prepend('Register')) {{-- prepend --}}
@php(title()->set('Register')) {{-- replace whole stack --}}

@section('content')

    <h1>
        Register
    </h1>

    ...

@endsection

You can have multiple title "stacks" under different keys. Default stack is using "default" as a key, but you are free to create new ones:

<title>{{ title('homepage') }}</title>

and later in Blade view:

@php(title('homepage')->append('Register'))

统计信息

  • 总下载量: 309
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-18