Join Joseph Lowery for an in-depth discussion in this video Understanding Laravel templating, part of Laravel 4 Essential Training.
- Laravel's built-in templating engine, Blade, is one of the most robust aspects of the framework. Now, before we begin coding with Blade, I wanted to take a few moments to review its most important features and capabilities. The Blade Templating Engine is one of two supported by Laravel, the other being the basic PHP file. A file is designated as a Blade template by being stored with a .blade.php extension.
Blade enjoys complete PHP support including both fully-formed PHP statements, and PHP functions such as date within Blade's recognized delimeters. The Blade syntax is very straightforward and easy to grasp. Double curly braces are used as the primary delimiters, and essentially equal a php echo statement. Use double curly braces in Blade to process variables, handle PHP functions such as substring, and also execute custom Laravel functions like link to.
Conditional Control is critical to any programming framework, and Laravel employs a simplified syntax, the @ symbol. With it you can integrate standard PHP @for statements, @foreach, note the use of the @ symbol for both the opening and closing indicators. You'll see the same pattern in most conditional operators. Also supported are @if, @else if, @else, @endif, and @while, @endwhile.
In addition, Laravel also includes a Conditional Control operator not available in PHP, @unless, which is basically the opposite of an if statement. Blade template structure is extremely flexible. You can incorporate external code snippets via the @include keyword. There's also extensive master page capabilities. Master pages are stored in the apps/views/layouts folder, and within a master page you can reserve an area of the page with the @yield keyword.
To display default content while keeping your options open, use @section, @show. To designate a child template include @extends at the top of that child template file. As you can tell, Blade comes with a great deal of power. We will begin exploring how to put that power to use in the next lesson.
Need a quick dive into Laravel? Check out this short primer, Up and Running with Laravel.
- Installing Laravel and Composer
- Routing requests
- Filtering routes
- Incorporating advanced controllers
- Creating a basic Blade template
- Developing a layout with child pages and forms
- Integrating a database
- Creating tables via migrations
- Outputting data
- Building a Laravel app
- Authenticating users
- Deploying Laravel code