The @section tag assumes that this will be rendered within some master layout file. (say master.blade.php)
What you need is a layout file that includes your doctypes, headers etc. Then have a
@yield('content')
in the location that you want the content to be output.
Then add at the top of your index.blade.php
@extends('master') //assuming master.blade.php is your master file and is located directly within the views directory
That should do the trick
Thanks Abhi, that was exactly the solution.
I had tried simple to write <?php ?> at the beginning and end, but then Laravel was giving me the unexpected '}' error, which I went searching through the internet and it gave the solution that I tried to do above.
So @section('content') only works if there is @yield('content') calling it? That makes sense to me. Is this correct? And thank you once more
abhiyanp said:
The @section tag assumes that this will be rendered within some master layout file. (say master.blade.php)
What you need is a layout file that includes your doctypes, headers etc. Then have a
@yield('content')
in the location that you want the content to be output.
Then add at the top of your index.blade.php
@extends('master') //assuming master.blade.php is your master file and is located directly within the views directory
That should do the trick
Blade doesn't need the php tags in it - blade files are essentially compiled into raw php equivalents (they are stored inside /app/views and exectuded from there) - so adding our own php tags breaks it.
And yes, foreach @section('section_name') is rendered using the corresponding @yield('section_name') directive in the main layout file. There are some nuances and edge cases of course but each section needs to be yielded somewhere.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community