Laravel blade append to section not working properly

Issue

I want to write to a region in my template from the view and also from an included view thing the first view but no matter what I try it doesn’t work. I have tried using @parent and @append but nothing has produced the result that I want so far.

In my layout I have the following:

@yield('scripts')

In my view primary I have the following:

@include('admin/rules/partials/_form')

@section('scripts)
    // javascript #1 here
@stop

In admin/rules/partials/_form I have the following:

@section('scripts)
    // javascript #2 here
@stop

So like I said I have tried using @parent after @section(‘scripts’) and also using @append instead of @stop but nothing I do includes the two script blocks properly. The best I’ve had so far is javascript #1 being included once and javascript #2 being included twice. How would I do this so that each block of code is appended to the scripts region only once?

Solution

I solved it in the end I had to do the following:

@yield('scripts')

In my view primary I have the following:

@include('admin/rules/partials/_form')

@section('scripts')
    // javascript #1 here
@stop

In admin/rules/partials/_form I have the following:

@section('scripts')
    @parent
    // javascript #2 here
@overwrite

Answered By – geoffs3310

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published