Stopping Injecting Content into a Section and Appending It

Problem

You want to stop injecting content into a Blade section.

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

Solution

Use the Blade @append 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 @append.

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

Then the following is output.

one
two

Discussion

You may want to use the command.

If you want to use the content of the previous section within your section, then see the Pulling in the Content of a Parent Section in Blade recipe.

comments powered by Disqus