Explore the versatility of Laravel's Blade templating engine with this comprehensive guide. From including views to conditional statements and outputting content, master every aspect to streamline your Laravel development workflow.
Description:
Unlock the full potential of Laravel's Blade templating engine with this comprehensive guide. Learn how to include views, use conditional statements, loop through data, output content, and more. Elevate your Laravel development skills with the power of Blade templating.
Explore the versatility of Laravel's Blade templating engine with this comprehensive guide. From including views to conditional statements and outputting content, master every aspect to streamline your Laravel development workflow.
# Blade Templating Engine in Laravel
Blade is a powerful and intuitive templating engine provided by Laravel,
which allows you to easily work with PHP code within your views. Below is an
overview of various Blade directives and features:
{{-- Show a section in a template --}}
@yield('name')
{{-- Indicates that the view extends a layout or master template --}}
@extends('layout.name')
{{-- Begin a section --}}
@section('name')
{{-- End a section --}}
@stop
{{-- End a section and yield its content --}}
@section('sidebar')
@show
{{-- Output the content of the parent section --}}
@parent
{{-- Include another view --}}
@include('view.name')
{{-- Include another view with data --}}
@include('view.name', array('key' => 'value'))
{{-- Translate a message --}}
@lang('messages.name')
{{-- Translate a message with pluralization --}}
@choice('messages.name', 1)
{{-- Conditional directives --}}
@if
@else
@elseif
@endif
{{-- Conditional directive for negated condition --}}
@unless
@endunless
{{-- Looping directives --}}
@for
@endfor
@foreach
@endforeach
@while
@endwhile
{{-- Forelse directive (4.2 feature) --}}
@forelse($users as $user)
@empty
@endforelse
{{-- Echo content --}}
{{ $var }}
{{-- Echo escaped content --}}
{{{ $var }}}
{{-- Echo unescaped content (Blade 5.0 feature) --}}
{!! $var !!}
{{-- Blade Comment --}}
{{-- Echoing Data After Checking For Existence --}}
{{{ $name or 'Default' }}}
{{-- Displaying Raw Text With Curly Braces --}}
@{{ This will not be processed by Blade }}