Using Laravel Blade’s @yield and @section directives

When you want to include content from various locations in your template files or loops, it can be useful in certain situations. For instance, in index.blade.php, you may require the content from master.blade.php. The result of this is as follows:
Solution 2 can be to use a stack in your scripts, which allows you to append as much content as required. To specify a directory, you can use the following example: if your main.blade.php is located in a particular directory, it could be something like:
Solution 2 suggests that you make changes to your code for ‘p’ like this:
From:
To:
Hopefully, this will work for you. The question is about trying to yield a section inside another section that has already been yielded in [unknown location], but it is not functioning correctly.

Question:

on my main.blade.php

@yield('content')

on my home.blade.php

@extends('main')
    @section('content')
    

this content should show on my main

@endsection

I am facing an issue where my @section content is not displaying despite having no errors. I am using Laravel 5.4 and cannot seem to figure out what could be causing this problem.



Solution 1:

Ensure that your main.blade.php and home.blade.php are located within the

resource/views/

directory.

Use the ” . ” symbol to indicate a different directory if it is not the same as the current directory.

Suppose the main.blade.php file is located at

resource/views/layouts

, in that case, the code snippet would resemble

@extends('layouts.main')

.


Solution 2:


It appears that an update to the code for

main.blade.ph

is necessary, specifically for the section related to variable “p”.

@yield('content')

To

@yield('content')

Hope this work for you

Frequently Asked Questions

Posted in Php