Explore tens of thousands of sets crafted by our community.
Laravel Blade Templating
25
Flashcards
0/25
@if ... @endif
Conditional statement. Sample usage: @if (
@empty ... @endempty
Check if a variable is empty. Sample usage: @empty(
@foreach ... @endforeach
Loop over each item in an array or collection. Sample usage: @foreach (item) <p>{{ item }}</p> @endforeach
{{ }}
Echo content with escaped HTML special characters. Sample usage: {{ price }}
@for ... @endfor
C-style for loop. Sample usage: @for (i < 10; i++) <p>{{ i }}</p> @endfor
@include('file_name')
Includes a Blade view from another file. Sample usage: @include('partials.footer')
@csrf
Generates an HTML hidden input field containing a CSRF token. Sample usage: <form>@csrf</form>
@isset ... @endisset
Check if a variable is set. Sample usage: @isset(
{!! !!}
Echo content with unescaped data. Be careful of XSS attacks. Sample usage: {!! htmlContent !!}
@unless ... @endunless
Inverse conditional statement. Sample usage: @unless (
@component('component_name') @endcomponent
Renders a Blade component. Sample usage: @component('alert') ... @endcomponent
@php ... @endphp
Execute a block of plain PHP within a template. Sample usage: @php
@json
Encode a PHP array to JSON. Sample Usage: @json(
@switch ... @endswitch
Switch statement. Sample usage: @switch(
@yield('section')
Output the content of a section. Sample usage: @yield('content')
@inject('service', 'App\Services\ServiceName')
Injects a service into a Blade template. Sample usage: @inject('metrics', 'App\Services\MetricsService')
@slot('name') ... @endslot
Fill a slot in a Blade component. Sample usage: @slot('title') My Title @endslot
@push('stack') ... @endpush
Append to a stack of content. Sample usage: @push('scripts') <script>alert('Hello')</script> @endpush
@guest ... @endguest
Content for unauthenticated users. Sample usage: @guest <p>Please log in.</p> @endguest
@error('field') ... @enderror
Show an error message for a form field. Sample usage: @error('email') <div>{{ message }}</div> @enderror
@stack('name')
Renders the entire stack of pushed content. Sample usage: @stack('scripts')
@can('permission') ... @endcan
Check if the user has a certain permission using Laravel's authorization system. Sample usage: @can('edit-posts') <button>Edit</button> @endcan
@section('name') ... @endsection
Define a section of content. Sample usage: @section('sidebar') ... @endsection
@verbatim ... @endverbatim
Escape Blade rendering within a block, allowing plain HTML. Sample usage: @verbatim <div>{{ This will not be processed by Blade }}</div> @endverbatim
@auth ... @endauth
Content for authenticated users. Sample usage: @auth <p>Welcome back!</p> @endauth
© Hypatia.Tech. 2024 All rights reserved.