【问题标题】:Laravel @section Does not seem to be workingLaravel @section 似乎不起作用
【发布时间】:2021-09-27 21:33:00
【问题描述】:

我有一个名为 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')
...

但现在的问题是,某些自定义样式似乎不起作用,@yield('style') 无法加载 css 样式。

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

【问题讨论】:

    标签: php laravel laravel-blade laravel-5.8


    【解决方案1】:

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

    内部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

    【讨论】:

      猜你喜欢
      • 2019-10-04
      • 2019-03-28
      • 2021-07-19
      • 2020-04-05
      • 2017-12-12
      • 2018-02-04
      • 2021-09-15
      • 2012-09-13
      • 1970-01-01
      相关资源
      最近更新 更多