Home /Laravel /Extending the master layout in blade

Extending the master layout in blade

We will now create a page that extends the master layout.

  1.  create a new page page.blade.php in /resources/views/page.blade.php
  2. add the following code
@extends(‘layouts.master’)

@section(‘title’, ‘Page Title’)

@section(‘sidebar’)

@parent

This is appended to the master sidebar.

@endsection

@section(‘content’)

This is my body content.

@endsection

HERE,

@extends(‘layouts.master’) extends the master layout
@section(‘title’, ‘Page Title’) sets the value of the title section.
@section(‘sidebar’) defines a sidebar section in the child page of master layout
@parent displays the contents of the sidebar section that is defined in the master layout
<p>This is appended to the master sidebar.</p> adds paragraph content to the sidebar section
@endsection ends the sidebar section
@section(‘content’) defines the content section
@section(‘content’) adds paragraph content to the content section
@endsection ends the content section

We will now add a route that tests our blade template

open /app/Http/routes.php
add the following route

Route::get(‘blade’, function () { return view(‘page’); });

Save the changes

Load the following URL in your web browser

http://localhost/larashop/public/blade

Leave a Reply