叶片附加部分

Laravel - blade append section

本文关键字:加部 叶片附      更新时间:2023-09-26

我需要在子视图中运行一个js脚本,所以我有一个部分与我所有的脚本,并在子视图中我尝试将我的脚本追加到现有的脚本。

HTML页面:

<html><head></head><body></body>@yield('scripts')</html>

:

@section('scripts') <!-- my standard scripts --> @stop

子视图:

@section('scripts') <!-- my new script --> @append

我已经尝试在子视图@section('scripts')中使用@parent,但不起作用。

谢谢

你的主视图必须有这样的脚本

@section('scripts')
    // your scripts here
@show

然后您可以使用@parent标记从子模板

section添加脚本
@section('scripts')
@parent
    // your other scripts
@endsection

只在刀片模板上阅读

我读过这个链接

<html>
<head>
    <title>App Name - @yield('title')</title>
</head>
<body>
    @section('sidebar')
        This is the master sidebar.
    @show
    <div class="container">
        @yield('content')
    </div>
</body>
</html>

父部分的示例代码

@extends('layouts.app')
@section('title', 'Page Title')
@section('sidebar')
@parent
<p>This is appended to the master sidebar.</p>
@endsection
@section('content')
    <p>This is my body content.</p>
@endsection

子视图使用上面的代码