简体   繁体   中英

laravel @yield is not rendering any result

I am a laravel beginner using the following: version 9.31.0 - macbook computer and composer however, @yield is not working when I'm using it in my code and I can't tell why. I tried changing the name of the content and using @endsection / @stop, but nothing seems to make it work.

no error is showing only the code is not working.

test.blade.php:

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

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h1>your user ID is: {{$userId}}</h1>

    <div>
        @yield('contentTest')
    </div>

</body>

</html>

taskContent.blade.php

@extends('test')

@section('contentTest')

<p>this is the test content yield</p>

@endsection

First you need to check your test file and contentTest is available in the same folder.

resources/views / all my blade views and check whether your routes are up to the mark or not.

// please check when you return your view file in routes or controller whatever it is you need to return the content file

$router->get('/page', function () {
    return view('content');
});

//your test.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>
        yield content from the test file
        @yield('contentTest')
    </div>
</body>
</html>

//your content.blade.php

@extends('test')
@section('contentTest')
<p>this is the test content yield show in content file</p>
@endsection

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM