简体   繁体   中英

laravel blade append to @section in @forelse

My main template blade has a @yield('section_name') in the <head> tag to append css/ js. Now I have a forelse like this:

@forelse($collection as $item)
    some text
    @section('section_name')
        // link to stylesheet
    @endsection
@empty
 // something went wrong
@endforelse

When this loops for like 5 times, only one stylesheet is added. After that, it seems like the @yield is not working anymore. Is there a way to make this work so I can keep appending items to that section?

Use @append instead of @endsection

@forelse($collection as $item)
    some text
    @section('section_name')
        // link to stylesheet
    @append
@empty
 // something went wrong
@endforelse

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM