Skip to main content
Directives are template instructions that start with #. Lex compiles them to plain PHP at build time — there is no runtime interpreter overhead.
To output a literal # character without triggering a directive, prefix it with a backslash: \#. Only \# followed immediately by a letter is treated as an escape. See Echo & comments for details.

Conditionals

#if / #elseif / #else / #endif

Use #if to conditionally render a block. You can chain as many #elseif branches as you need, and add a final #else fallback.
#if($user->isAdmin())
    <p>Admin panel</p>
#elseif($user->isModerator())
    <p>Moderator panel</p>
#else
    <p>Guest view</p>
#endif
All standard PHP expressions are valid inside the parentheses, including method calls, comparisons, and logical operators.

#unless / #endunless

#unless renders its block when the condition is falsy. It is the inverse of #if and reads more naturally in some situations.
#unless($user->isVerified())
    <p>Please verify your email address before continuing.</p>
#endunless

Existence checks

#isset / #endisset

Renders its block only when the variable is set and not null — equivalent to PHP’s isset().
#isset($sidebar)
    <aside>{{ $sidebar }}</aside>
#endisset

#empty / #endempty

Renders its block only when the variable is empty — equivalent to PHP’s empty().
#empty($notifications)
    <p>No new notifications.</p>
#endempty

Switch

Use #switch / #case / #default / #endswitch for multi-branch matching. The expression inside #case can be any PHP value: a string literal, a variable, a class constant, etc.
#switch($order->status)

    #case('pending')
        <span class="badge-yellow">Pending</span>
    #break

    #case('processing')
        <span class="badge-blue">Processing</span>
    #break

    #case('shipped')
    #case('delivered')
        <span class="badge-green">{{ $order->status }}</span>
    #break

    #default
        <span class="badge-gray">Unknown</span>

#endswitch
Omitting #break between #case blocks enables fall-through, identical to PHP’s switch behaviour.

Raw PHP blocks

Use #php / #endphp to embed arbitrary PHP logic directly in a template. This is useful in standalone PHP projects that need inline calculations or variable preparation.
#php
    $total   = array_sum(array_column($items, 'price'));
    $tax     = $total * 0.1;
    $display = number_format($total + $tax, 2);
#endphp

<p>Total (inc. tax): ${{ $display }}</p>
#php blocks are disabled in sandbox mode. If your application allows user-submitted templates, enable sandbox mode to prevent arbitrary code execution.

Debug helpers

Two directives are available for inspecting values during development:
DirectiveBehaviour
#dump($var)Calls var_dump() and continues rendering
#dd($var)Calls var_dump() then halts execution with exit(1)
#dump($user)

#dd($response)
Remove all #dump and #dd calls before deploying to production. Neither directive is gated by environment — they will output to your live page if left in.

Build docs developers (and LLMs) love