If I have a layout called RightSideBar.blade.php
in Laravel blade
, one area yield('content')
and the other yield('sidebar')
.
Is there a built in way to display a default partial
if the view that is extending RightSideBar
does not have a section('sidebar')
?
I know you can pass a value by default, just wondering if there is a way to make default a partial.
In Laravel, @yield is principally used to define a section in a layout and is constantly used to get content from a child page unto a master page.
The main advantage of using the blade template is that we can create the master template, which can be extended by other files.
@yield is a section which requires to be filled in by your view which extends the layout. You could pass it a default value through the second parameter if you'd like. Usages for @yield could be the main content on your page. @section is a section which can contain a default value which you can override or append to.
You've also learned the basics of Laravel blade that you need to be able to collaborate with a team of Laravel Devs as a frontend Dev. Be sure to visit the Laravel docs to study more about the blade templates and how you can use Layouts to minimize unnecessary repetitions.
Yes you can pass a default
Looking at the documentation
@yield('sidebar', 'Default Content');
Which basically puts a default output when the child template does not have @section('sidebar')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With