Laravel blade: Can you yield a default partial

user3238419 picture user3238419 · Jul 3, 2014 · Viewed 19.8k times · Source

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.

Answer

lozadaOmr picture lozadaOmr · Jul 4, 2014

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