【发布时间】:2020-04-21 03:26:14
【问题描述】:
我有一个需要一些自定义 js 和样式的部分子视图。这个孩子是整个应用程序中唯一使用它的视图。它很复杂,所以 JS 被分解成自己的文件。
我尝试将脚本和样式“注入”到父布局according to the docs 中,但它似乎不起作用。我已经厌倦了这些部分中@parent 和@@parent 的组合。我尝试将主要布局,@yield('scripts') @yield('styles') 更改为 @section('scripts')@show。
我错过了什么?这甚至可能吗?
main.blade.php(为简洁起见)
<head>
@include('apps.includes.styles')
@yield('styles')//a place for custom style
</head>
<body>
@yield('content')
@include('apps.includes.scripts')
@yield('scripts') //a place for custom scripts
</body>
create.blade.php
@extends('layouts.main')
@section('styles')@endsection
@section('scripts')@endsection
@section('content')
<div>
@include('partials._toolbar')
</div>
@endsection
_toolbar.blade.php
@section('styles')
@parent
<script src="{{asset('assets/css/mystyle.css')}}"></script>
@endsection
@section('scripts')
@parent
<script src="{{asset('assets/js/myjs.js')}}"></script>
@endsection
<section>
// my toolbar html code
</section>
【问题讨论】:
标签: php laravel laravel-5 laravel-blade laravel-6