Table of contents
In this post, you will learn about the Laravel 9 blade section with an example. Laravel blade @section
is a directive that will able us to inject content layout from the extended blade. The content of the section will show the layout using the @yield
directive.
Â
Now let's create a folder layouts
inside resources/views
and then create a file master.blade.php
.
Â
resources/views/layouts/master.blade.php
<!DOCTYPE html>
<html>
<head>
<title>@yield('title') - App Name</title>
</head>
<body>
<div class="container">
@yield('content')
</div>
</body>
</html>
Â
Then next let's create our child blade inside resources/views
usually, it is home, contact, page, etc.
Â
As you can see we use @extends
, and @section
directives. For more about Laravel Blades kindly visit their documentation here: https://laravel.com/docs/9.x/blade.
Â
resources/views/page_name.blade.php
@extends('layouts.master')
@section('title', 'Page Title')
@section('content')
<p>This is your content body.</p>
@endsection
Â
I hope it helps. If you want to know about Laravel blade templating you can visit our previous tutorial here.
Read next