The Blade is a powerful templating engine in a Laravel framework. The blade allows to use the templating engine easily, and it makes the syntax writing very simple. The blade templating engine provides its own structure such as conditional statements and loops. To create a blade template, you just need to create a view file and save it with a .blade.php extension instead of .php extension. The blade templates are stored in the /resources/view directory. The main advantage of using the blade template is that we can create the master template, which can be extended by other files.
Why Blade template?
Blade template is used because of the following reasons:
In blade template, we do not need to write the code between <?php echo $variable; ?>. The above syntax is equivalent to <?= $variable ?>.
The above syntax is equivalent to <?= isset($variable) ? $variable : ?default value? ?>
Blade Template Control Statements
Blade templating engine also provides the control statements in laravel as well as shortcuts for the control statements.
Blade template provides @unless directive as a conditional statement. The above code is equivalent to the following code:
The blade templating engine also provides the @hasSection directive that determines whether the specified section has any content or not.
Let's understand through an example.
The blade templating engine provides loops such as @for, @endfor, @foreach, @endforeach, @while, and @endwhile directives. These directives are used to create the php loop equivalent statements.
In the above code, we are passing the students array to the student.blade.php file.