There is several php template engine but Blade template engine is the most popular and simplistic way to write php code along with HTML. The popular Laravel Framework use it out of the box. If you are laravel developer then you already know how cool the Blade syntax. If you are not a Laravel developer you are also be impressed with Blade syntax after see the few examples.
In the WordPress template, where we need to write php code along with HTML then you know as a WordPress developer how the scenario is. Let's take a look a simple example but when it will be a big code it will be more complex. After showing some code example I'll show you how to integrate the blade template engine to your WordPress theme just 3 simple steps.
In normal PHP with HTML
<?php for($i;$i<5;$i++) {
if($i==2){ ?>
<p> Name: <?php echo $name; ?>
<?php } else { ?>
<p>Value: <?php $i; ?></p>
<?php } ?>
<? } ?>
In Blade syntax, you can do it with simple clean syntax and elegant way.
@for($i;$i<5;$i++)
@if($i==2)
<p> Name: {{$name}} </p>
@else
<p> Value: {{$i}} </p>
@endif
@endfor
Let's see more examples.
foreach
loop
@foreach($data as $row)
<div>
Name: {{$row->name}} <br>
Age: {{$row->age}} <br>
</div>
@endforeach
if-else
Conditional statement
@if($condition)
<p> Smith </p>
@else
<p> Adam </p>
@endif
include
file
@include('abc.php')
wpquery
WordPress loop
@wpquery(array('post_type' => 'post'))
{{the_title()}}
@wpempty
<p> No post found </p>
@wpend
To know more about Blade template documentation
Step 01: Download Blade template
Step 02: Extract the downloaded folder and copy the blade folder then paste the folder into your WordPress theme.
Step 03: Now open the functions.php
file and simply include the line include("blade/blade.php")
Finished! Now you can use blade syntax in your WordPress theme.