簡體   English   中英

Laravel - 刀片附加部分

[英]Laravel - blade append section

我需要在子視圖中運行 js 腳本,所以我有一個包含所有腳本的部分,並且在子視圖中我嘗試將我的腳本附加到現有腳本中。

網頁:

<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

只需閱讀下面的刀片模板 laravel 鏈接

我讀過這個鏈接

<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

對於子視圖,請使用上面的代碼

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM