I want to include a header blade file in my template, but I keep getting an "undefined variable $slot" error.
P粉596161915
P粉596161915 2023-08-06 17:23:03
0
1
545
<p>I'm currently running into a problem using Laravel's Blade template. I have successfully created a template file and expanded it in different pages. However, when I try to include the header and footer in the child Blade template, I encounter a "Variable $slot is not defined" error message. <br /><br />I have used @yield() to define each section in the template file. In the specific Blade template, I use @section() to fill in the content of the corresponding section. <br /><br />Here's how I tried to include the header in the child Blade template: <br /><br />Using @include('header')<br /> Tried using @component('header') @endcomponent<br /> Unfortunately, both methods resulted in the same "undefined variable $slot" error, and my header didn't show up. <br /><br />How should I correctly include the header in the child Blade template without getting the "variable $slot is not defined" error and ensure it displays as expected? I would be very grateful for any insights or solutions to this problem. Thanks! </p><p><br /></p>
P粉596161915
P粉596161915

reply all(1)
P粉546179835

Please do the following in your main file:

<HTML>
<head></head>
<body>
@yield('section')
</body>
</html>

In another file

@extends('layouts.app')
@section('section')
    <p>This is appended to the master sidebar.</p>
@endsection

You can read more at https://laravel.com/docs/10.x/blade#extending-a-layout

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!