Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Gch's avatar
Level 1

@yield

Hello, I have implemented a simple code just to try using "@yield", that is the code:

  • The parent file:
Laravel @yield('containertest')

@section ( 'containertest') Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore dolore magna aliqua and. Ut enim ad minim veniam, quis nostrud laboris nisi ut exercitation ullamco aliquip ex ea commodo consequat. Duis aute Irure in dolor velit esse reprehenderit in voluptate cillum dolore nulla had fugiat pariatur. Excepteur sint occaecat cupidatat not proident, sunt in culpa who officiated deserunt abated anim id est Laborum. @endsection

==> The contents of the section 'containertest' does not appear

When I test another code I found that "@yield ( 'containertest')" is ignored.

Where is the problem in this case ?

0 likes
31 replies
JeffreyWay's avatar

Please update your post with a better title. "view" isn't useful.

1 like
Gch's avatar
Level 1

The parent template 'test': .... return view('test');

Gch's avatar
Level 1

yes the two files have the extension ".blade.php"

Snapey's avatar

You render the child for the view and then the child defers to the parent or master layout.

The master layout is then rendered until it comes to a yield, at which point it includes the content from the child.

suppose you have master.blade.php;

<html>
    <head>
        <title>@yield('title')</title>
    </head> 
    <body>
        @yield('content')
    </body>
</html>

and then you have an about us page at about.blade.php

@extends('master')

@section('title')
About Us
@endsection

@section('content')
    <div>my about us page here</div>
@endsection

Then in the controller

return view('about');    //not master
Gch's avatar
Level 1

I implemented your example, the error that I had is:

ErrorException in C: \ wamp \ www \ Laravel \ vendor \ Laravel \ framework \ src \ Illuminate \ View \ FileViewFinder.php line 137: View [app] not found. (View: C: \ wamp \ www \ Laravel \ resources \ views \ about.blade.php)

Gch's avatar
Level 1

I get an error :

ErrorException in C: \ wamp \ www \ Laravel \ vendor \ Laravel \ framework \ src \ Illuminate \ View \ FileViewFinder.php line 137: View [app] not found. (View: C: \ wamp \ www \ Laravel \ resources \ views \ about.blade.php)

tomopongrac's avatar

It says that view file dont exist ... do you create app.blade.php?

Gch's avatar
Level 1

No, the "view" folder contains:

  • "Welcome.blade.php" file,
  • the two folders : "errors" and "vendor".
  • the parent template,
  • the child template ,

I did not create any other template

tomopongrac's avatar

Can you post your view files which generate error (about.blade.php)

Snapey's avatar

My example is to point you in the right direction. Not just copy it literally.

Just make sure you return view('child') and not the parent

If you want more help, I suggest you post your code instead of 'parent and 'child'

Gch's avatar
Level 1

Hello, I apologize for the delay, the code is:

  • routes.php :
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

Route::get('/', function () {
    return view('welcome');
});

Route::get('/1/{name}', 'Homecontroller@test');
  • Homecontroller.php :
<?php

namespace App\Http\Controllers;

class Homecontroller extends Controller
{

public function index()
{
  return view('home');
}

public function test($name)
{
  return view('testc');
}

}
  • views/testc.blade.php :
@extends('layouts.testp')

@section('content')
    <div>my about us page here</div>
@endsection
  • views/layouts/testp.blade.php :
@extends('layouts.testp')

@section('content')
    <div>my about us page here</div>
@endsection

Thank you, in advance for your valuable assistance.

DNAngel's avatar

Route.php

Route::get('/1/{name}', 'uses' => 'Homecontroller@test');

Homecontroller.php

namespace App\Http\Controllers;

class Homecontroller extends Controller {

    public function index() {
        return view('home');
    }

    public function test($name) {
        return view('testc', $name);
    }
}

views/testc.blade.php :

@extends('layouts.testp')

@section('content')
    <div>{{ $name about us page here }}</div>
@stop

views/layouts/testp.blade.php :

@section('content')
1 like
thefuzzy0ne's avatar

@stop is just shorthand for @endsection. They should both be interchangeable.

BladeCompiler.php:

/**
  * Compile the end-section statements into valid PHP.
  *
  * @param  string  $expression
  * @return string
  */
protected function compileEndsection($expression)
{
    return '<?php $__env->stopSection(); ?>';
}

// ...

/**
  * Compile the stop statements into valid PHP.
  *
  * @param  string  $expression
  * @return string
  */
protected function compileStop($expression)
{
    return '<?php $__env->stopSection(); ?>';
}

Are these guys twins, or what? :)

Gch's avatar
Level 1

Thank you for your reply, but I get an error : " FatalErrorException in routes.php line 18: syntax error, unexpected '=>' (T_DOUBLE_ARROW) ".

In testp.blade.php file, where can I write

@yield (content) 

??

thefuzzy0ne's avatar

I am thefuzzy0ne - psychic extraordinaire! Nah! Just kidding. That's why I have absolutely no idea what in your routes.php.

thefuzzy0ne's avatar

...And yes, @yield('content') for into the parent view, so that that section can be overridden by it's child views (views that @extend() it).

Gch's avatar
Level 1

@thefuzzy0ne, Route.php

<?php
Route::get('/', function () {
    return view('welcome');
});

Route::get('/1/{name}', 'uses' => 'Homecontroller@test');

Homecontroller.php

namespace App\Http\Controllers;

class Homecontroller extends Controller {

    public function index() {
        return view('home');
    }

    public function test($name) {
        return view('testc', $name);
    }
}

views/testc.blade.php :

@extends('layouts.testp')

@section('content')
    <div>{{ $name about us page here }}</div>
@stop

views/layouts/testp.blade.php :

<!DOCTYPE html>
<html>
    <head>
      <meta charset="utf-8">
    </head>
    <body>
        @yield('content')
    </body>
</html>
thefuzzy0ne's avatar

There's your problem!

Route::get('/1/{name}', 'uses' => 'Homecontroller@test');

should be:

Route::get('/1/{name}', ['uses' => 'Homecontroller@test']);
Gch's avatar
Level 1

@thefuzzy0ne another error :

    "   ErrorException in Factory.php line 167: array_merge(): Argument #2 is not an array     " 
thefuzzy0ne's avatar

OK, here's that problem! :-)

class Homecontroller extends Controller {

    // ...

    public function test($name) {
        return view('testc', ['name' => $name]); // Expects an array as the second parameter
    }
}

Or neater still:

class Homecontroller extends Controller {

    // ...

    public function test($name) {
        return view('testc', compact('name')); // Expects an array as the second parameter
    }
}

One more thing, by convention, generally it should be HomeController not Homecontroller. Either will work, but I think one is more readable.

Snapey's avatar

and here's a problem

@extends('layouts.testp')

@section('content')
    <div>{{ $name about us page here }}</div>  //  you have invalid content here  {{ $name }} or {{ 'about us page here' }}
@stop

Gch's avatar
Level 1

Thank you, but I get another error (after rectification) :

" ErrorException in FileViewFinder.php line 137: View [app] not found. (View: C:\wamp64\www\Laravel\resources\views\testc.blade.php) "

Gch's avatar
Level 1

Thank you, but I get another error (after rectification) :

 ErrorException in FileViewFinder.php line 137: View [app] not found. (View: C:\wamp64\www\Laravel\resources\views\testc.blade.php) "
thefuzzy0ne's avatar

Sounds like you've modified the source of testc.blade.php and you're trying to extend or include a view that doesn't exist.

Gch's avatar
Level 1

Here views/testc.blade.php :

@extends('layouts.testp')

@section('content')
    <div> {{ $name }} </div>
@stop

I have made no changes !!!!

DNAngel's avatar

As it is telling you that, it can't locate the app.blade.php. You might have included it somewhere-else.

To solve that issue, you can create app.blade.php in view folder.

<!DOCTYPE html>
    <head>
        <meta charset='utf-8'>
        <title>About Page</title>
    </head>
    <body>
        @section('content')
        @stop
    </body>
</html>
Next

Please or to participate in this conversation.