Reputation: 246
I use the Bladetemplate of Laravel. Is there a way to set different header for different views with only one include in master.blade.php?
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
Upvotes: 0
Views: 3850
Reputation: 425
In your main layout
<title>@yield('title','Home')</title>
Then In your views Just call
@section('title','My View 1')
@section('title','My View 2')
The second parameter in yield is the default if none defined.
Upvotes: 0
Reputation: 40899
If you want to include different header templates for different views, there is no need to include anything from your layout. Instead, include the proper header template into a separate section in your views and then display that section in the master template:
master.blade.php
@yield('header')
@yield('content')
viewA.blade.php
@extends("layouts.master")
@section('header')
@include('headerA')
@stop
@section('content')
view content
@stop
viewB.blade.php
@extends("layouts.master")
@section('header')
@include('headerB')
@stop
@section('content')
view content
@stop
This way, each of your views includes different header templates into the header section that will be later displayed in master layout with @yield('header').
Upvotes: 3