Skip to content

Control Structures

Directive Role
@if / @elseif / @else / @endif Conditionals
@unless / @endunless Inverted conditional
@isset(expr) / @endisset Body when expr evaluates to not None
@empty(expr) / @endempty Body when expr is empty / falsy
@foreach(items as item) / @endforeach Loop with loop helpers
@forelse / @empty / @endforelse Loop or empty state
@for / @endfor Python for header
@while / @endwhile While loop
@auth / @endauth Body when auth_user or __authenticated is set
@guest / @endguest Inverse of @auth
@can / @cannot / @canany / @cannotany Gate / policy checks — see Authorization
@python / @endpython Escape hatch

Inside @foreach / @forelse, loop exposes: index, iteration, remaining, count, first, last, even, odd, depth, parent.

resources/views/welcome.prism.html
@foreach(users as user)
<li @if(loop.first)class="first"@endif>{{ user.name }}</li>
@endforeach

Bare @empty inside @forelse remains the empty branch. Standalone @empty(expr)@endempty is a separate empty-check directive.

resources/views/partials/nav.prism.html
@auth
<p>Welcome back</p>
@endauth
@guest
<a href="/login">Sign in</a>
@endguest
@can('update', post)
<a href="/edit">Edit</a>
@endcan

@can / @cannot / @canany call the authorization gate.

resources/views/welcome.prism.html
@lang("messages.welcome", {"name": name})
{{ __("messages.welcome", {"name": name}) }}

__, trans, and trans_choice are injected into every template context.