Showing posts with label Laravel Layout. Show all posts
Showing posts with label Laravel Layout. Show all posts

Saturday, February 11, 2017

Simple Laravel Layouts using Blade

The most part of Laravel is usage of layout. It helps you to design a better application. You can create a layout and use that for view pages. Below is a good & simple example how you can create and use layouts.

At first create file named "test.blade.php" under "resources/views/layouts" folder with following contents:


<!DOCTYPE html>
<html>
    <head>
        <title>Title - @yield('title')</title>      
    </head>

    <body>
        <section>
            @yield('content')                
        </section>
        <section>
            @yield('pageScript')
        </section>
    </body>
</html>

The use of the layout file would be as like (from any resources blade file):


@extends('layouts.test') //This line will include layout file

@section('title', 'Title of the page') //Set title of the page

@section('content') //Start content of the page
Html content goes here
@stop //End content of the page

@section('pageScript') //Start javascript of the page
<script src="{{ asset('/js/some-js-file.js') }}"></script>

<script>
$(document).ready(function () {
    
});
</script>
@stop //End javascript of the page