Home > Net >  Inserting yield and sections
Inserting yield and sections

Time:10-12

i have layout.blade.php file :

<!DOCTYPE html>
<html lang="pl">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>PraktSite</title>
    @vite('resources/css/app.css')
</head>

<body>
        @yield('content')
        @yield('header')
    </div>
</body>

</html>

Next to him there is header.blade.php file :

@extends('layout')

@section('header')
    <h2>TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT</h2>
@stop

And finally again next to him home.blade.php

@extends('layout')

@section('content')
    <h2>
            @foreach ($ludzie as $czlowiek)
                <h3> <a href="user/{{ $czlowiek['id'] }}"> {{ $czlowiek['imie'] }} </a> </h3>
            @endforeach
    </h2>
@stop

What is the problem?

Result on site is that i can't see 'header' section, only 'content'. Real magic. What am i missing?

CodePudding user response:

Your home blade should be fine as long as you're returning that view. But your layout and header blades need a bit of tweaking.

For the header blade, remove all of the blade directives. They aren't necessary here. Header will never be accessed directly, so it doesn't need to extend anything. You're also not passing anything in, so it doesn't need to be part of the section.

 <h2>TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT</h2>

For the layout, change @yield to @include for the header, so it just grabs that file and places it where you want it. Included files will still have access to anything the parent (in this case, home) has.

<body>
        @include('header')
        @yield('content')
    </div>
</body>
  • Related