Reputation:
I have moved the code of header from a template in /views/layouts/header.blade.php
. When I call it using,
@yield('layouts.header')
or
@yield('header')
It doesn't display the code.
Upvotes: 0
Views: 1562
Reputation: 1
**master layout code**
<html>
<body>
@include('layouts.header')
<main>
@yield('content')
</main>
@include('layouts.footer')
</body>
*view blade page code*
@extends('master')
@section('content')
<h1>Hello world</h1>
@endsection
Upvotes: 0
Reputation: 379
You should use @include('views.layouts.header')
in your page.
@yield
is used for templates or master pages when you want to extend the section in other pages.
Upvotes: 0
Reputation: 35180
You should use [@include][1]
not @yield
. @yield
is meant for when you're rendering a @section
whereas @include
is meant for simply adding a file.
Base
<body>
@include('layouts.header')
<main>
@yield('content')
</main>
@include('layouts.footer')
</body>
Child
@extends('master')
@section('content')
<h1>Hello world</h1>
@stop
The only reason you would use @yield
for the header is if you're having a different header section in all of your child components.
Upvotes: 3