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 >
@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
CodePudding user response:
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 >
@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