首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >@yield在主页上工作,但不在使用相同布局的其他页面上工作

@yield在主页上工作,但不在使用相同布局的其他页面上工作
EN

Stack Overflow用户
提问于 2020-07-08 00:36:19
回答 1查看 37关注 0票数 0

这件事真的让我抓狂了。我希望一双新的眼睛能发现我的错误。

我在每个页面上都有一个部分标题,但标题只在home.blade.php上显示,而不显示在其他页面上。

master.blade.php

代码语言:javascript
复制
<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}">
    <head>
        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
        <meta name="csrf-token" content="{{ csrf_token() }}" />
        <title>@yield('title')</title>
        @stack('styles')
    </head>
    <body class="bg-light">
        <div class="container-fluid h-100">
            @yield('app')
        </div>
        @include('sweetalert::alert')
        {{ Session::forget('alert') }}
        @stack('scripts')
    </body>
</html>

app.blade.php

代码语言:javascript
复制
@extends('layout.master')

@prepend('styles')
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
    <link rel="stylesheet" type="text/css" href="{{ URL::asset('css/overrides.css') }}" />
@endprepend

@section('app')
        <div class="row">
            <div class="col-12 no-padding">
                @include('layout.includes.header')
            </div>
        </div>
        <div class="row h-100">
            <div class="col-12">
                <!-- Begin nav/content row --> 
                <div class="row h-100">
                    <div id="sidebar-wrapper" class="visible">
                        @include('layout.includes.nav')
                    </div>
                    <!-- Begin main column -->
                    <div class="col content" style="overflow-x:auto;">
                        @if (Request::path() === '/')
                        <div class="row no-padding">
                            <div class="col d-none d-sm-block">
                                <h4>@yield('content-heading')</h4> <!-- [my @yield directive is here] -->
                            </div>
                            <div class="col flex-grow-1">
                                @include('layout.includes.searchform')
                            </div>
                        </div>
                        @endif
                        <div class="row no-padding inner-box shadow p-3 mb-5 bg-white rounded">
                            @yield('content')
                        </div>
                    </div>
                    <!-- END main column-->
                </div>
                <!-- END nav/content row-->
            </div>
        </div>
@endsection

@prepend('scripts')
    @include('layout.js.footer-js')
    @yield('form-js')
@endprepend

home.blade.php

代码语言:javascript
复制
@extends('layout.app')

@section('title', 'Asset Management')

@section('content-heading', 'View All Assets') //This works

@section('content')

                            <div class="table-responsive">
                                <table class="table table-striped text-nowrap">
                                <caption>Recently Added Assets</caption>
                                    <thead>
                                        <tr>
                                            <th scope="col">Tag #</th>
                                            <th scope="col">Type</th>
                                            <th scope="col">Device</th>
                                            <th scope="col">Serial #</th>
                                            <th scope="col">Assigned</th>
                                            <th scope="col">To</th>
                                            <th scope="col">Status</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                @foreach ($assets as $asset)
                                        <tr>
                                            <td>{{ $asset->asset_tag }}</td>
                                            <td>{{ $asset->cat_name }}</td>
                                            <td>{{ $asset->man_name }} {{ $asset->model_name  }}</td>
                                            <td>{{ $asset->serial  }}</span></td>
                                            <td>{{ \Carbon\Carbon::parse($asset->assign_date)->format('D M d, Y g:iA')  }}</td>
                                            <td>{{ $asset->name  }}</td>
                                            <td>{{ $asset->status }}</td>
                                        </tr>
                                @endforeach
                                    </tbody>
                                </table>
                            </div>

@endsection

@section('form-js')
    
@endsection

@push('scripts')

@endpush

我的其他页面的布局都与home.blade.php相同,例如:

代码语言:javascript
复制
@extends('layout.app')

@section('title', 'Checkout Asset')

@section('content-heading', 'Checkout Asset') //Does not output to template

@section('content')
Content here...
@endsection

@push('scripts')
@endpush

为什么<h4>@yield('content-heading')</h4>只在home.blade.php上工作?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-08 03:36:47

显示@yield('content-heading')的代码包含在:

代码语言:javascript
复制
@if (Request::path() === '/')
...
@endif

这将显示仅限于该url。

:)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62779942

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档