Laravel 5 Tutorial : Blade Template to Create layout in Laravel

Laravel 5 Tutorial : how to create layout in Laravel 5 using Blade Templating to include all master pages, Konwing blade template syntax in Laravel 5.

Laravel 5 Tutorial - Blade is default template engine from Laravel Artisan PHP Framework. Blade is a simple to use. Blade offers an easier syntax and brief for use in generating an HTML document.

Please Read :
  1. Routing Basics in Laravel
  2. Basic Controllers in laravel
  3. Understanding Views in Laravel

Blade Syntax in Laravel

Checking with "if else, looping array" to display any data, and updating the echo variable is the task we did when creating the web apps. Laravel know it needs, then they create the blade to make it easier.
Blade Template

Here is blade syntax examples in Laravel

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Login Data</title>
  </head>
  <body>
    <h2>There is the login data :</h2>
    @if(count($logindata))
      <ul>
      @foreach($logindata as $login)
        <li> {{ $login }} </li>
      @endforeach
      </ul>
    @endif
  </body>
</html>

Iteration using Blade

...
@for ($x = 0; $x < 10; $x++)
    <strong>x value = {{ $i }}</strong>
@endfor

@foreach ($datas as $data)
    <b>Value = {{ $data->title }}</b>
@endforeach

@while (true)
    <b>do looping</b>
@endwhile
...

Using Blade in Conditionally

...
@if (count($logindata))
    // do anything
@elseif (count($logindata) > 1)
    // do anything
@else
    // do anything
@endif
...

How The Blade working?

To be able to use the blade at your laravel project's, you must rename Views file from "filename.php" to "filename.blade.php" in resources\views\ folder.

The examples above will shows how the blade working and just replace the php tag wording into a simpler and fewer characters. In fact there're other features that will leave you dumbfounded and more fell in love with blade, namely inheritance templates and section overwrite.

Example Project using Blade Templates
Create a master template and save it at resources\views\layouts\master.blade.php

master.blade.php

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>@yield('title')</title>
    <link href="https://fonts.googleapis.com/css?family=Lato:100" rel="stylesheet" type="text/css">
    <style>
        html, body {
            height: 100%;
        }
        body {
            margin: 0;
            padding: 0;
            width: 100%;
            display: table;
            font-weight: 100;
            font-family: 'Lato';
        }
        .container {
            text-align: left;
            display: table-cell;
        }
        .content {
            text-align: center;
            display: inline-block;
        }
        .title {
            font-size: 16px;
        }
    </style>
  </head>
  <body>
    @section('sidebar1')
    <h2>This is the Sidebar1 master.</h2>
    <div class="container">
      @yield('content')
    </div>
    @section('sidebar2')
    <h2>This is the Sidebar2 master.</h2>
  </body>
</html>

Now, create another view and extend the master template and save it at resources\views\blade-example.blade.php

blade-example.blade.php

@extends('master')
@section('title', 'Blade Templating')
@section('content')
  <h2>{{$name}}</h2>
  <p>This is my body content.</p>
@stop

Now, add new route to app/Http/routes.php

routes.php 

Route::get('/blade', function () {
   return view('blade-example', array('name' => 'www.hc-kr.com'));

Then, you can execute the URL with your browser and tell me what happend.
See you next Lessons..

COMMENTS

Next Recomended


Feel free to code it up and send us a pull request.

Hi everyone, let's me know how much this lesson can help your work. Please Subscribe and Follow Our Social Media 'kodeajaib[dot]com' to get Latest tutorials and will be send to your email everyday for free!, Just hit a comment if you have confused. Nice to meet you and Happy coding :) all ^^



Follow by E-Mail


Name

ADO.NET,3,Ajax,6,Android,9,AngularJS,4,ASP.NET,4,Blogger Tutorials,7,Bootstrap,7,C++,1,Codeigniter,2,Cplusplus,6,Crystal Report,6,CSharp,25,Ebook Java,2,FlyExam,1,FSharp,3,Game Development,2,Java,35,JDBC,2,Laravel,84,Lumen,2,MariaDB,2,Ms Access,3,MySQL,31,ODBC,6,OleDB,1,PHP,14,PHP Framework,5,PHP MYSQLI,9,PHP OOP,5,Python,8,Python 3,4,SQL Server,4,SQLite,4,Uncategorized,5,Vb 6,2,Vb.Net,89,Video,48,Vue Js,4,WPF,2,Yii,3,
ltr
item
KODE AJAIB: Laravel 5 Tutorial : Blade Template to Create layout in Laravel
Laravel 5 Tutorial : Blade Template to Create layout in Laravel
Laravel 5 Tutorial : how to create layout in Laravel 5 using Blade Templating to include all master pages, Konwing blade template syntax in Laravel 5.
https://4.bp.blogspot.com/-sCGKraNvAqE/V8CDc7x8i2I/AAAAAAAACVE/_BKObnOzdS8xBSGxRwR7VE_ksIfqoChUQCLcB/s320/templating-blade-laravel5-1.png
https://4.bp.blogspot.com/-sCGKraNvAqE/V8CDc7x8i2I/AAAAAAAACVE/_BKObnOzdS8xBSGxRwR7VE_ksIfqoChUQCLcB/s72-c/templating-blade-laravel5-1.png
KODE AJAIB
https://www.kodeajaib.com/2016/08/laravel-5-tutorial-blade-templates.html
https://www.kodeajaib.com/
https://www.kodeajaib.com/
https://www.kodeajaib.com/2016/08/laravel-5-tutorial-blade-templates.html
true
3214704946184383982
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy