Yielding the Current Section in a Blade Template

Problem

You want to yield the contents of the section you're currently in.

Solution

Use the Blade @show command.

This ends the current section and yields it. Yielding means this is the point the content of the section will be output.

@section('one')
  Something here
  But we'll end it, so it won't output
@stop

@section('two')
  Something else
@show

The HTML output from above would be.

Something else

Discussion

You can think of @show as a @stop followed by a @yield('section').

comments powered by Disqus