Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel blade: Can you yield a default partial

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.

like image 420
user3238419 Avatar asked Jul 03 '14 09:07

user3238419


People also ask

What is yield in Laravel blade?

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.

What is the advantage of Laravel blade template?

The main advantage of using the blade template is that we can create the master template, which can be extended by other files.

What is the difference between yield and section in Laravel?

@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.

Is Laravel blade frontend?

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.


1 Answers

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')

like image 96
lozadaOmr Avatar answered Sep 20 '22 19:09

lozadaOmr