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 :
Here is blade syntax examples in Laravel
Iteration using Blade
Using Blade in Conditionally
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
Now, create another view and extend the master template and save it at resources\views\blade-example.blade.php
blade-example.blade.php
Now, add new route to app/Http/routes.php
routes.php
Then, you can execute the URL with your browser and tell me what happend.
See you next Lessons..
Please Read :
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.
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