【问题标题】:laravel @include not working for section('script')laravel @include 不适用于部分('脚本')
【发布时间】:2021-07-12 16:54:15
【问题描述】:

我的产量或部分或包含在这里不起作用是我的代码,我认为我已经遵守了所有规则。如您所见,我想调用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

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    在 index.blade.php 中

    @extends('layouts.master')
    
    @section('content')
    
    @include('Home.steps.one')
    @include('Home.steps.two')
    @include('Home.steps.three')
    
    
    @endsection
    

    对于脚本和 css,您可以使用 @stack。所以在 master.blade.php 中代替

    @yield('script')
    

    使用

    @stack("script")
    

    two.blade.php 或任何主扩展布局中使用

    @push('script')
    <script>
    
    </script>
    @endpush
    

    【讨论】:

      【解决方案2】:

      @John Lobo 是正确的,@stack@push 绝对是这里的路。但这里还可能发生另一件事。看起来您正在尝试使用 jQuery,但我没有看到它被导入到任何地方。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-08-05
        • 2016-06-21
        • 2016-11-13
        • 1970-01-01
        • 2019-10-11
        • 1970-01-01
        • 2018-06-18
        • 1970-01-01
        相关资源
        最近更新 更多