Laravel Part-6
Laravel Part-6
---------------------------------------------------------------------------
Layout : -
1. Layout is used to reduce the code redundancy. It also helps to manage
the code in a more efficient way.
There are two ways to create layout:-
a. Layout using Component.
b. Layout using template inheritance.
</x-index>
</x-index>
Extending layout:-
Create blade view file: - resources/views/home.blade.php
@extends('layout.adminlayout')
@section('title','Home')
@section('page_name') <h1>Home Page</h1> @endsection
@section('banner')<h2>This is home banner page</h2>@endsection
@section('main') <h2>This is hone page main
content</h2>@endsection
@section('default-content')
@parent
<h4>This is home page text</h4>
@endsection
1. @extends Blade directive to specify which layout the child view should
“inherit”.
2. Views which extends a Blade layout may inject content into the
layout’s sections using @section directives.
3. The contents of sections will be displayed in the layout using @yeild
4. The @endsection directive will only define a section while @show will
define and immediately yield the section.
5. @parent directive to append (rather than overwriting ) content to the
layout. The @parent directive will be replaced by the content of the
layout when the view is rendered.
Example:-
Create blade view file : - resources/views/layout/admin.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>@yield('title')</title>
</head>
<body>
@yield('page-name')
@yield('banner')
@yield('main')
@section('banner')
<h2> This is banner page </h2>
@endsection
@section('main')
<h2> This is main page content </h2>
@endsection
{{-- layout la content and apna content dono karne ke liye --}}
@section('default-content')
@parent
<h3>This is home page default page</h3>
@endsection