user379888
user379888

Reputation:

yield not displaying content in laravel

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

Answers (3)

Amandeep Singh
Amandeep Singh

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

Mohamad Pishdad
Mohamad Pishdad

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

Rwd
Rwd

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.

@include docs

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

Related Questions