Layout Blade Directives | Setup Layout in Laravel 9 | @yield, @section, @include, @extends, @push, @endpush, and @stack Guide | How to Use Them Explained
Layout Blade Directives
First of all buid laravel project by executing - these commands
Then open routes>web.php and create some functions
Then create a directories like as follows
Following three files inside layouts directory
Inside main.blade.php
@include('layouts.header')
@yield('main-section')
@include('layouts.footer')
Inside header.blade.php
@stack('title')
Inside footer.blade.php
Following files inside views directory
Inside home.blade.php
Home Page
@endsection
Inside about.blade.php
@extends('layouts.main')
@push('title')
About Page
@endpush
@section('main-section')
About Page
@endsection
Inside courses.blade.php
Courses Page
@endsection
Inside services.blade.php
@extends('layouts.main')
@push('title')
Services Page
@endpush
@section('main-section')
Services Page
@endsection
Now run your project. Now you have little idea about how these all directives works.
1. @yield directives is used to display the contents of a given section.
2. @section and @endesction directive, defines a section of content.
3. @extends blade directive to specify which layout the child view should "inherit".
4. @stack to render the complete stack contents, pass the name of the stack to the @stack directives.
5. @push and @endpush is used to push data into the stack.

Comments
Post a Comment