Ok, my @yield or @extends is not working because some reason

82 Views Asked by At

I just wanna print something thanks to @yield in my layout (cristarium), but for some reason is doing nothing, it just appear the text MASTER but don't HELLO.

VIEWS FOLDER LOCATIONS

resources\views\ffxiii-2\cristarium.blade.php

resources\views\ffxiii-2\cristarium_personajes\noel_kreiss.blade.php

ROUTE IN WEB.PHP

Route::get('/ffxiii-2/cristarium', function () {
    return view('ffxiii-2.cristarium');
})->name('cristarium');

LAYOUT -> cristarium.blade.php

<!DOCTYPE html>
<html lang="es">
<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>Cristarium</title>
</head>

<body>
    MASTER
    <div class="container">
        @yield('content')
    </div>
</body>
</html>

BLADE TO PRINT -> noel_kreiss.blade.php

@extends('ffxiii-2.cristarium')

@section('content')
    HELLO
@endsection

I tried to change the name's folder avoiding the underscore, and changing to the - in ffxiii-2, but still don't work, so I think that's not the problem.

2

There are 2 best solutions below

1
Rooneyl On BEST ANSWER

Views cascade the other way.

Your route is showing the view which renders the file ffxiii/cristarium.blade.php,
this is your master layout.

What you need to do is to return the view ffxiii-2/cristarium_personajes/noel_kreiss from the route, which will the render that view, which in turn includes your master layout.

E.g.

Route::get('/ffxiii-2/cristarium', function () {
    return view('ffxiii-2.cristarium_personajes.noel_kreiss');
})->name('noel_kreiss');
0
Rouhollah Mazarei On

You are returning the layout file in your controller method. But I think you should return the second file (noel_kreiss.blade.php):

Route::get('/ffxiii-2/cristarium', function () {
    return view('ffxiii-2.cristarium_personajes.noel_kreiss');
})->name('cristarium');