Blade templating engine in laravel 5

Writing html code with standard php where you write too many php and html tags. This type of code may be complicated, messy and less readable. That's why lot of developers using blade templates in laravel.

Blade is a simple and powerful templating engine. Every blade template must use .blade.php extention.

If you getting Error: Class 'Illuminate\Html\HtmlServiceProvider' not found. Then add Form/html package in laravel.

If you don't know how to add new package them you can find solution, Check Add Form/html package in laravel5.

Look at this simple example :-


Route::get('user', function() {
    $users = App\User::all();
    return view('userDir.users', compact('users'));



<!DOCTYPE html>
    <title>User list page</title>

<h1>Our User List</h1>

// with standard php 
foreach( $users as $user ){
	echo '<li>'.  $user->name .'</li>';

// with Blade templating engine
@foreach($users as $user)
    <li>{{ $user->name }}</li>


Look at above code, Trying to show difference between standard php code and blade engine code, Its very clear blade syntax is too much clean.

Just Keep in mind :

{{ }} :: <?php= ?> and never put semicolon(;) between those braces.

@ :: <?php ?>

{!! !!} :: For escape html characters  

// {!! !!} for escape html characters
    <li>{!! link_to( "user/{$user->name}", $user->name ) !!}</li>

// Another example 
{!! '<script>alert('Hello, World!);</script>' !!}


If statements with standard php syntax:

	<p>something is true</p>
	<p>something is false</p>


If statements with blade syntax:

You may find much cleaner than above code here we stripped out <?php ?> and several curly braces.

      <p>something is true</p>
      <p>something is false</p>


Unless syntax with blade:

@unless (Auth::check())
    You are not signed in.



For Loop:

@for( $i=1; $i<100; $i++ )
	<p>Number {{ $i }} is less than 100</p>

While Loop:



Something to say? Tell us in comment section.