Laravel – All the Blade Template Commands

Laravel - All the Blade Template Commands

Laravel – All the Blade Template Commands, comes handy for a quick reference. Some of you may have difficulties to find blade template commands.
So, this list contains almost every commands, that we can use on blade template.Take a look.

{{– Comment –}} – A Blade comment
{{ $var }} – Echo content
{{{ $var }}} – Echo escaped content
{{ $var or ‘default’ }} – Echo content with a default value

@extends(‘layout’) – Extends a template with a layout

@foreach($list as $key => $val) – Starts a for each block
@endforeach – Ends a for each block

@for($i = 0; $i < 10; $i++) – Starts a for block
@endfor – Ends a for block

@if(condition) – Starts an if block
@else – Starts an else block
@elseif(condition) – Start a elseif block
@endif – Ends a if block

@while(condition) – Starts a while block
@endwhile – Ends a while block

@unless(condition) – Starts an unless block
@endunless – Ends an unless block

@include(file) – Includes another template
@include(file, [‘var’ => $val,…]) – Includes a template, passing new variables.

@each(‘file’,$list,’item’) – Renders a template on a collection
@each(‘file’,$list,’item’,’empty’) – Renders a template on a collection if collection is empty.

@yield(‘section’) – Yields content of a section.
@show – Ends section and yields its content
@lang(‘message’) – Outputs message from translation table
@choice(‘message’, $count) – Outputs message with language pluralization

@section(‘name’) – Starts a section
@stop – Ends section
@endsection – Ends section

@append – Ends section and appends it to existing of section of same name
@overwrite – Ends section, overwriting previous section of same name

@push(name) – push a block of markup
@endpush – End for push
@stack(name) – Pull out all those view-specific scripts in the layout

Thanks for reading.

Leave a Comment

Your email address will not be published. Required fields are marked *