Support the ongoing development of Laravel.io →
posted 10 years ago
Forms
Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

kronus kronus Joined 22 Nov 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.