Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel blade append to section not working properly

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?

like image 936
geoffs3310 Avatar asked Jun 11 '15 15:06

geoffs3310


1 Answers

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
like image 92
geoffs3310 Avatar answered Oct 14 '22 02:10

geoffs3310