简体   繁体   English

Laravel:从子文件夹扩展父文件夹中的文件

[英]Laravel: extend a file in parent folder from subfolder

i want to extend the master.blade.php located in views\backend folder.我想扩展位于views\backend 文件夹中的master.blade.php。

view/backend/master.blade.php <--i want to extend this file view/backend/master.blade.php <--我想扩展这个文件

view/backend/partials/header.blade.php <--the file that will extend the master.blade.php view/backend/partials/header.blade.php <--将扩展 master.blade.php 的文件

folder structure文件夹结构

  • views意见
    • backend后端

      -master.blade.php -master.blade.php

      • partials部分

        -header.blade.php -header.blade.php

        -footer.blade.php -footer.blade.php

        -sidebar.blade.php -sidebar.blade.php

I tried this in the header.blade.php file but fail:我在 header.blade.php 文件中尝试了这个但失败了:

@extends('backend.master')

Edited master.blade.php编辑master.blade.php

<body>
    <div class="wrapper">
        @yield('header')
        @yield('sidebar')
        @yield('content')
        @yield('footer')
    </div>
  </body>

header.blade.php header.blade.php

@extends('backend.master')

@section('header')
<p> this is the header</p>
@endsection

The page shows master content only in the browser该页面仅在浏览器中显示主内容

Normally header , footer and sidebar contain the markup which remain common across pages.通常页眉页脚侧边栏包含跨页面通用的标记。 Only the content varies from page to page.只有内容因页面而异。

Also the concept of extending master layout is to avoid repeating the shared parts across various pages.此外,扩展布局的概念是避免在各个页面之间重复共享部分。 Using @yield('header') @yield('footer') @yield('sidebar') defeats the concept of extending master layout.使用@yield('header') @yield('footer') @yield('sidebar')违背了扩展布局的概念。 Because then all those sections need to be included on all pages.因为所有这些部分都需要包含在所有页面上。

So you master layout should be like所以你的主布局应该是这样的

<body>
    <div class="wrapper">
        @include('backend.partials.header')
        @include('backend.partials.sidebar')
        @yield('content')
        @include('backend.partials.footer')
    </div>
</body>

Then for any page you can extend the master layout as然后对于任何页面,您都可以将布局扩展为

@extends('backend.master')

@section('content')

<!-- content markup here -->

@endsection

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM