Stopping Injecting Content into a Section and Overwriting

Problem

You want to stop injecting content into a Blade section.

And you want the content overwrite to any previous section of the same name.

Solution

Use the Blade @overwrite command.

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

The above Blade template will output the following.

one

But if you change the second @stop to an @overwrite.

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

Then the following is output.

two

Discussion

The @overwrite command is one of the four ways to end a section.

The other three commands are:

  1. @stop - Stopping Injecting Content Into a Section.
  2. @show - Yielding the Current Section in a Blade Template.
  3. @append - Stopping Injecting Content into a Section and Appending It.
comments powered by Disqus