简体   繁体   中英

Laravel @section Does not seem to be working

I have a Blade named dashboard.blade.php which goes like this:

@extends( 'frontend.dashboard_main' )

@section('title')  Profile  @endsection
@section('style')
   SOME CUSTOM STYLES
@endsection

And dashboard.blade.php goes like this:

@include( 'frontend.header' )
...

And at header.blade.php , I added these:

<head>
<title>@yield('title')</title>
@yield('style')
...

But now the problem is, SOME CUSTOM STYLES does not seem to be working and @yield('style') not loads css styles.

So if you know what's going wrong here, please let me know...

For including css and js files in extended view .Better use stack instead of yield

Inside frontend/dashboard_main

 <header>
other css files and meta
@stack('styles')
</header>

and in extended view

@push('styles')
   <style>

</style>
@endpush

Ref: https://laravel.com/docs/5.8/blade#stacks

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