在 Laravel 中包含布局

时间:2021-03-04 07:44:48

标签: php laravel laravel-blade

我的 master.blade.php 文件如下

<body>
    @include('layouts.header')
    @yield('content')
    @include('layouts.footer')
    @include('layouts.footer-script')
</body>

我的 dashboard.blade.php 文件如下

@extends('layouts.master')

// I would like to add Menu here

@section('content')

//more code here

@endsection

我的 menu.blade.php 如下所示。

@extends('dashboard')

@section('menu')

// more HTML code
@endsection

如何在 Menu 中添加 dashboard.blade.php

3 个答案:

答案 0 :(得分:0)

dashboard.blade.php 文件如下

 @extends('layouts.master')
    
    
    @include('menu')
    
    @section('content')
    
    //more code here
    
    @endsection

menu.blade.php 如下所示。

 <div>
    
    // more HTML code
 </div>

答案 1 :(得分:0)

如果您的菜单是静态的,只需将其用作包含

仪表盘文件

    @extends('layouts.master')
    @section('content')
    @include('layouts.menu')
    @endsection

和菜单文件将是 (menu.blade.php)

  <a href=''>Home</a>

答案 2 :(得分:0)

master.blade.php

<body>
  @include('layouts.header')
  @yield('content')
  @include('layouts.footer')
  @include('layouts.footer-script')
</body>

dashboard.blade.php

    @extends('layouts.master')
    @include('menu')
    @section('content')
    //more code here
    @endsection

这是您的代码。 这很好。 如果这是错误,我认为menu.blade.php的路径一定是错误的。

例如:@include(frontend.menu)

感谢您的回答。