Laravel 拉拉维尔5号收益率和;部分

Laravel 拉拉维尔5号收益率和;部分,laravel,view,laravel-5,Laravel,View,Laravel 5,我的结构如下: - master.blade { @yield('menu') // here I load the one and only menu I have @yield('content') // here I load different pages } - menu.blade { @extends('master') @section('menu') main menu @stop } - other pages using the same format { @e

我的结构如下:

- master.blade {

@yield('menu') // here I load the one and only menu I have

@yield('content') // here I load different pages

}

- menu.blade {
@extends('master')

@section('menu')
main menu
@stop
}

- other pages using the same format {
@extends('master')

@section('content')
here is the content
@stop
}
由于某些原因,菜单未加载。你知道为什么吗?我尝试加载菜单,然后翻页。这很简单,但出于某种原因,我不明白为什么它不起作用

  • master.blade
    布局中使用
    @include('menu')
    而不是
    @yield('menu')

  • 菜单中删除
    @extends
    @节(“菜单”)
    @stop
    。刀片

  • 在这些更改之后,您的代码应该如下所示:

    主刀片

    @include('menu'))
    @产量(‘含量’)
    
    菜单。刀片

    主菜单
    
    其他页面

    @extends('master'))
    @节(“内容”)
    内容如下
    @停止
    
    了解有关模板的更多信息:


    顺便说一句,你可以用
    @endsection
    代替
    @stop
    ,这对我来说更具可读性

    流程应如下所示:

    - master.blade {
    
    @include('menu') // here I load the one and only menu I have
    
    @yield('content') // here I load different pages
    
    }
    
    - menu.blade {
    
       Markup for the main menu
    
    }
    
    - other pages using the same format {
    @extends('master')
    
    @section('content')
       here is the content
    @stop
    }
    

    创建简单的菜单文件并将其包含在主模板中,yield用于动态内容。

    如果您对我下面的答案满意,请接受它:)