簡體   English   中英

laravel @include 不適用於 section('script')

[英]laravel @include not working for section('script')

我的 yield 或 section 或 include 在這里不起作用是我的代碼,我想我已經遵循了所有規則。 如您所見,我想調用three.blade.php,我將其命名為@section('script') 並使用yield('script') 將其調用到master.blade.php,但似乎是yield 或section不管用。 下面是我的代碼:

master.blade.php

<!doctype html>
<html lang="fa" dir="rtl">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <link href="{{ asset('themes/css/bootstrap.rtl.min.css') }}" rel="stylesheet">
    <link href="{{ asset('themes/css/bootstrap-select.css') }}" rel="stylesheet">
    <link href="{{ asset('themes/fontawesome/css/all.min.css') }}" rel="stylesheet">
    <link href="{{ asset('themes/css/style.css') }}" rel="stylesheet">
    <link href="{{ asset('favicon.ico') }}" rel="shortcut icon" type="image/x-icon"/>
    <title> كاربران</title>
</head>
<body>
@include('Home.layouts.sidebar')
<main id="app">
    @include('Home.layouts.header')
    @yield('content')
</main>
@include('Home.layouts.footer')
@yield('script')
</body>
</html>

index.blade.php

@include('Home.steps.one')
@include('Home.steps.two')
@include('Home.steps.three')

二.blade.php

<form action="{{ route('book.store') }}" method="post">
    @csrf
    ....
</form>

<table class="table table-striped">
    ....
</table>

@section('script')
    <script>
        $(document).on('click', '#book_id', function() {
            alert('Hello');
        });
    </script>
@endsection

三.blade.php

<form action="{{ route('requisition.store') }}" method="post">
    @csrf
    ....
</form>

<table class="table table-striped">
    ....
</table>

@section('script')
    <script>
        $(document).on('click', '#province_id', function() {
            alert('Hello');
        });
    </script>
@endsection

在 index.blade.php 中

@extends('layouts.master')

@section('content')

@include('Home.steps.one')
@include('Home.steps.two')
@include('Home.steps.three')


@endsection

對於腳本和 css,您可以在master.blade.php使用@stack而不是

@yield('script')

@stack("script")

並在two.blade.php或任何主擴展布局中使用

@push('script')
<script>

</script>
@endpush

@stack Lobo是正確的, @stack@push絕對是通往這里的路。 但這里也可能發生另一件事。 看起來您正在嘗試使用 jQuery,但我沒有看到它被導入到任何地方。

暫無
暫無

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

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