Laravel dynamic page title in navbar-brand

前端 未结 2 434
不思量自难忘°
不思量自难忘° 2020-12-15 08:44

I have layouts.app.blade.php where I have my and tags and also the

相关标签:
2条回答
  • 2020-12-15 09:11

    If this is your master page title below

    <html>
    <head>
        <title>App Name - @yield('title')</title>
    </head>
    <body>
        @section('sidebar')
            This is the master sidebar.
        @show
    
        <div class="container">
            @yield('content')
        </div>
    </body>
    

    then your page title can be changed in your blade page like below

    @extends('layouts.master')
    
    @section('title', 'Page Title')
    
    @section('sidebar')
    @parent
    
    <p>This is appended to the master sidebar.</p>
    @endsection
    
    @section('content')
    <p>This is my body content.</p>
    @endsection
    

    More information can be found here Laravel Docs

    0 讨论(0)
  • 2020-12-15 09:12

    You can pass it to a view for example

    Controller

    $title = 'Welcome';
    
    return view('welcome', compact('title'));
    

    View

    isset($title) ? $title : 'title';
    

    or php7

    $title ?? 'title';
    

    Null coalescing operator

    0 讨论(0)
提交回复
热议问题