Blade master pages

There are some parts of a web page content that don’t really change across each pages. But blade is capable of to contain those contents in one place and call them every time.

Below code have nothing special just writing code with all html tags.

resources/view/userDir/users.blade.php

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>User list page</title>
    <link rel="stylesheet" href="style.css" /></head>
</head>
<body>
<h1>Our User List</h1>
@foreach($users as $user)
    <li>{!! link_to( "user/{$user->name}", $user->name ) !!}</li>
@endforeach
</body>
</html>

 

Now, we will try the same thing with use of master page.

Creating a master file resources/view/master.blade.php

<!-- Header start -->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>User list page</title>
    <link rel="stylesheet" href="style.css" /></head></head>
<body>
<!-- Header end -->

// Only yield section will always change in every view file 
// Other section (header and footer) always be same in every view file
@yield('content')

<!-- Footer start -->
</body>
</html>
<!-- Footer end -->

@yield ('content')  this is dynamic part of every web page. It will change according to working or active web page.   

After this change you will find blade templating is getting more cleaner.

Now our resources/view/userDir/users.blade.php file transformed like:

@extends('master')

@content
<h1>Our User List</h1>
@foreach($users as $user)
    <li>{!! link_to( "user/{$user->name}", $user->name ) !!}</li>
@endforeach

@stop

 

 

Something to say? Tell us in comment section.