Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save icheernoom/03145d6af7e324375de8d541acce09d2 to your computer and use it in GitHub Desktop.
Save icheernoom/03145d6af7e324375de8d541acce09d2 to your computer and use it in GitHub Desktop.
Laravel Blade Template Cheatsheet
<ul>
<li><code>{{ $var }}</code> - Echo content</li>
<li><code>{{ $var or 'default' }}</code> - Echo content with a default value</li>
<li><code>{{{ $var }}}</code> - Echo escaped content</li>
<li><code>{{-- Comment --}}</code> - A Blade comment</li>
<li><code>@extends('layout')</code> - Extends a template with a layout</li>
<li><code>@if(condition)</code> - Starts an <strong>if</strong> block</li>
<li><code>@else</code> - Starts an <strong>else</strong> block</li>
<li><code>@elseif(condition)</code> - Start a <strong>elseif</strong> block</li>
<li><code>@endif</code> - Ends a <strong>if</strong> block</li>
<li><code>@foreach($list as $key =&gt; $val)</code> - Starts a <strong>foreach</strong> block</li>
<li><code>@endforeach</code> - Ends a <strong>foreach</strong> block</li>
<li><code>@for($i = 0; $i &lt; 10; $i++)</code> - Starts a <strong>for</strong> block</li>
<li><code>@endfor</code> - Ends a <strong>for</strong> block</li>
<li><code>@while(condition)</code> - Starts a <strong>while</strong> block</li>
<li><code>@endwhile</code> - Ends a <strong>while</strong> block</li>
<li><code>@unless(condition)</code> - Starts an <strong>unless</strong> block</li>
<li><code>@endunless</code> - Ends an <strong>unless</strong> block</li>
<li><code>@include(file)</code> - Includes another template</li>
<li><code>@include(file, ['var' =&gt; $val,...])</code> - Includes a template, passing new variables.</li>
<li><code>@each('file',$list,'item')</code> - Renders a template on a collection</li>
<li><code>@each('file',$list,'item','empty')</code> - Renders a template on a collection or a different template if collection is empty.</li>
<li><code>@yield('section')</code> - Yields content of a section.</li>
<li><code>@show</code> - Ends section and yields its content</li>
<li><code>@lang('message')</code> - Outputs message from translation table</li>
<li><code>@choice('message', $count)</code> - Outputs message with language pluralization</li>
<li><code>@section('name')</code> - Starts a section</li>
<li><code>@stop</code> - Ends section</li>
<li><code>@endsection</code> - Ends section</li>
<li><code>@append</code> - Ends section and appends it to existing of section of same name</li>
<li><code>@overwrite</code> - Ends section, overwriting previous section of same name</li>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment