Site icon MageComp Blog

How to Create Blade Template Layout in Laravel

How to Create Blade Template Layout in Laravel

Hello Laravel Friends,

Today we will learn about How to Create Blade Template Layout in Laravel.

The blade is a templating engine for the Laravel framework. Blade templating engine makes writing syntax easy and comfortable. Laravel Blade Template allows developers to create HTML-based smooth designs and themes. All the individual pages can extend the master template created with the blade template.

To create blade templates you just need to save your view file with the .blade.php extension rather than .php. Blade templates reside in the resources/views directory. Let’s find out How to Create Blade Template Layout in Laravel

Steps to Create Blade Template Layout in Laravel:

Step 1: Create a folder of your project name in the resources\views folder.

Step 2: Create layouts\partials folder in project_name folder

Step 3: Create header.blade.php, footer.blade.php and script/stylesheet.blade.php as per the requirement at the below path

resources\views\project_name\layouts\partials

Step 4: Create mainlayout.blade.php in the below path

resources\views\project_name\layouts

And add the following code to add header, footer, script, and stylesheet file

<!DOCTYPE html>
<html>
<head>
    <title>Project Name </title>
    @include('project_name.layouts.partials.stylesheet')//include stylesheet file
    @yield('styles') // for page specific stylesheet
</head>

<body>

@include('project_name.layouts.partials.script') // include script file
@include('project_name.layouts.partials.header') // include header file

@yield('content') //content part of page

@include('project_name.layouts.partials.footer') // include footer file

@yield('scripts') // for page specific script
</body>
</html>

Step 5: Include the mainlayout file as per your requirement and add sections.

@extends('project_name.layouts.mainlayout')
@section('styles')
//page specific style
@endsection
@section('content')
// write your page content here
@endsection
@section('script')
// code for page specific script
@endsection

Conclusion:

This way you can Create Blade Template Layout in Laravel. If you face any difficulty reach me via the comment box and Hire Dedicated Laravel Developers for your custom requirement. Stay tuned for the upcoming Laravel solutions.

Happy Coding

Exit mobile version