2017-10-28 104 views
0

我使用Laravel的Bladetemplate。有沒有辦法爲不同的視圖設置不同的標題,只有一個包含在master.blade.php中?不同視圖中的不同標題(刀鋒模板,Laravel)

master.blade.php

@include("elements.header") 
    @yield('content') 
    @section("footer") 
    @show 

view.blade.php

@extends("layouts.master") 
    @section("title") 

    @stop 
    @section("content") 
    @include("elements.error") 

    @section("footer") 
    @include("elements.footer") 
    @stop 

回答

2

如果要包括不同的看法不同的頭模板,有無需包含佈局中的任何內容。相反,包括適當的報頭模板到在你的意見一個單獨的部分,然後顯示的是,在主模板部分:

master.blade.php

@yield('header') 
@yield('content') 

viewA.blade .PHP

@extends("layouts.master") 

@section('header') 
    @include('headerA') 
@stop 

@section('content') 
    view content 
@stop 

v iewB.blade.php

@extends("layouts.master") 

@section('header') 
    @include('headerB') 
@stop 

@section('content') 
    view content 
@stop 

這樣,每個的你的意見包括不同報頭模板進部,將與@yield(「報頭」)後顯示在主佈局。