Master Template in laravel

Master template means a template which has a header, footer and sidebar. We prepare it in the form of a structure. It has only one dynamic part in which the data keeps on changing frequently and the rest of the part remains static. We call it master template.

It is very easy to create a master template in Laravel and we create fewer master templates so that our header remains the same, our footer remains the same, our sidebar remains the same, only the content part keeps changing, the rest of the website does not change, that is why we use the master template.

This is how to create a master template in Laravel:

  • Create a folder suppose name of folder is ‘master’.
  • Create some files here like header.blade.php, footer.blade.php & master.blade.php.
  • In master.blade.php

A. First Way

In master.blade.php

@include('master.header')
<title>@yield('title')</title>

@yield('content')

@include('master.footer')
In index.blade.php

@extends('master.master')

@section('title', 'Homepage')
@section('content')
hi this is front page

@endsection

 

A. Second Way

In index.blade.php

@extends('master.master')

@push('head')
<title>home</title>
@endpush
@section('content')
hi this is front page

@endsection

 

In master.blade.php

@include('master.header')
<head>@stack('head')</head>

@yield('content')

@include('master.footer')

 

Leave a Reply