Laravel blade: Can you yield a default partial

Although the docs specifies a default only as a string you can in fact pass a view

@yield('sidebar', \View::make('defaultSidebar'))

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


Most of the time we want multiple line default content, we can use this syntax:

@section('section')
    Default content
@show

For example I have this in the template file:

@section('customlayout')
    <article class="content">
        @yield('content')
    </article>
@show

You can see the difference between @show and @stop/@endsection: the above code is equivalent to the one below:

@section('customlayout')
    <article class="content">
        @yield('content')
    </article>
@stop

@yield('customlayout')

In the other view files I can either set the content only:

@section('content')
    <p>Welcome</p>
@stop

Or I can also set a different layout:

@section('content')
    <p>Welcome</p>
@stop
@section('defaultlayout')
    <div>
        @yield('content')
    </div>
@stop

The @stop is equivalent as the @endsection.