Description #
Blade is a clean and powerful templating engine provided with Laravel, the popular PHP web framework. It allows developers to write expressive templates using familiar HTML and embedded directives.
History #
Blade was introduced in 2011 as part of the Laravel framework by Taylor Otwell. It was created to offer a more elegant alternative to raw PHP templates, providing a syntax similar to other popular templating engines but deeply integrated with Laravel’s features and routing system.
Hello World Code #
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
</head>
<body>
<h1>{{ 'Hello, World!' }}</h1>
</body>
</html>
How to Run #
Option 1: Online
Use a Laravel playground like https://laravelplayground.com/
Option 2: Local
Install Laravel using Composer:
composer create-project laravel/laravel myapp
cd myapp
php artisan serve
Place Blade code in a .blade.php
file inside the resources/views
folder and render via a controller.
Key Concepts #
- Extension of
.blade.php
files - Interpreted by Laravel before being cached as PHP
- Uses
{{ }}
for output,@
directives for control structures - Clean syntax for loops (
@foreach
) and conditionals (@if
) - Supports template inheritance with
@extends
and@section
- Blade components and slots
- Deep integration with Laravel’s routing and controllers
- Can include partials with
@include
- Automatically escapes variables for XSS safety
- Caches views for performance
Try It Online #
Fun Facts #
- Despite being a Laravel feature, Blade is so popular that some developers extract it for use in non-Laravel PHP projects.
- The
@
symbol is key to all Blade directives, keeping syntax intuitive and clean. - Blade views are converted into compiled PHP for efficiency, but developers rarely need to touch that layer.
Resources #
Official site
Docs or tutorial
GitHub or interpreter
Community or learning resources