Laravel @section 似乎不起作用

时间:2021-07-20 10:58:46

标签: php laravel laravel-blade laravel-5.8

我有一个名为 dashboard.blade.php 的 Blade,它是这样的:

@extends( 'frontend.dashboard_main' )

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

dashboard.blade.php 是这样的:

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

header.blade.php,我添加了以下内容:

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

但现在的问题是,SOME CUSTOM STYLES 似乎不起作用,@yield('style') 无法加载 css 样式。

所以如果你知道这里出了什么问题,请告诉我......

1 个答案:

答案 0 :(得分:1)

用于在扩展视图中包含 cssjs 文件。最好使用堆栈而不是产量

内部frontend/dashboard_main

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

并在扩展视图中

@push('styles')
   <style>

</style>
@endpush

参考:https://laravel.com/docs/5.8/blade#stacks