【问题标题】:Laravel yield and section not working properly showing blankLaravel 产量和部分无法正常工作显示空白
【发布时间】:2022-12-24 15:41:26
【问题描述】:

在我的项目中,laravel yield 和 section 无法正常工作

主页(app.blade.php)

<body>
        @include('admin.layout.header')

        <div class="wrapper">
            <div class="container">
                @yield('content')
            </div>
        </div>
        <!-- jQuery  -->
        <script src="{{asset('public/AdminAssets/assets/js/jquery.min.js')}}"></script>
        <script src="{{asset('public/AdminAssets/assets/js/bootstrap.min.js')}}"></script>
</body>

仪表板.blade.php

@extends('admin.layout.app') @section('内容') 页面标题 -->

今天 昨天 上个星期
    <h4 class="page-title">Dashboard</h4>
</div>
@endsection

地址食谱.blade.php

@extends('admin.layout.app')
@section('content')
<!-- BASIC WIZARD -->
        <div class="dropdown pull-right">
            <a href="#" class="dropdown-toggle card-drop" data-toggle="dropdown" aria-expanded="false">
                <i class="zmdi zmdi-more-vert"></i>
            </a>
            <ul class="dropdown-menu" role="menu">
                <li><a href="#">Action</a></li>
                <li><a href="#">Another action</a></li>
                <li><a href="#">Something else here</a></li>
                <li class="divider"></li>
                <li><a href="#">Separated link</a></li>
            </ul>
        </div>
@endsection

航线

--first one for my homepage
Route::get('/', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
 
--second one for my recipe page which one not rendering in app.blade.php file
Route::get('/addrecipe', [App\Http\Controllers\RecipeController::class, 'AddRecipeDb'])->name('AddRecipe');

上面的代码我有一个主页(父)app.blade.php 页面,我有 2 个其他子页面,我想在母版页上使用 Laravel 中的 @yield 和 @section 方法呈现页面信息,我使用了它但它仍然没有在职的。

如果有人帮助找出或解决这个问题,那将对我有很大帮助。

提前致谢。

【问题讨论】:

  • 我认为您需要改用@push,因为您有多个@section('content'),最新的部分将覆盖之前的部分。
  • 什么“工作不正常”?实际发生了什么,你期望发生什么?

标签: php laravel laravel-8 laravel-9


【解决方案1】:

我试图在 app.blade.php 上反映该页面,因此我需要包含该文件。我的错误是我也在扩展包含文件的布局,所以这就是它不起作用的原因。

谢谢大家的支持❤

【讨论】:

    猜你喜欢
    • 2021-10-01
    • 2013-08-14
    • 2014-06-27
    • 1970-01-01
    • 1970-01-01
    • 2018-04-25
    • 1970-01-01
    • 2019-01-07
    • 1970-01-01
    相关资源
    最近更新 更多