简体   繁体   中英

Laravel: extend a file in parent folder from subfolder

i want to extend the master.blade.php located in views\backend folder.

view/backend/master.blade.php <--i want to extend this file

view/backend/partials/header.blade.php <--the file that will extend the master.blade.php

folder structure

  • views
    • backend

      -master.blade.php

      • partials

        -header.blade.php

        -footer.blade.php

        -sidebar.blade.php

I tried this in the header.blade.php file but fail:

@extends('backend.master')

Edited master.blade.php

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

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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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