Stopping Injecting Content Into a Section

Problem

You're finished with a Blade section, but don't want to output it yet.

Solution

Use the Blade @stop command to end the section.

@section('nav')
  <ul>
    <li><a href="#">link 1</a></li>
    <li><a href="#">link 2</a></li>
  </ul>
@stop

Now your template will have a section named nav which you can output later with a @yield command.

Discussion

Note that this doesn't append to existing sections.

If you want to append to an existing section, end the section with @append.

The @stop command does not overwrite existing sections.

Imagine you had the following Blade template.

@section('test')
   one
@stop
@section('test')
   two
@stop
@yield('test')

What would be output is.

one

You can use the comment to pull in the contents of the previous section. See the Pulling in the Content of a Parent Section in Blade recipe.

comments powered by Disqus