Blade syntax reference
Every directive, expression, and path rule the static build supports — plus what is deliberately unavailable and how to fix a template that will not compile.
This page is the complete list. If something is not here, it does not compile.
The rule behind the list is simple: your website is static, so anything that would need a server running at the moment a visitor arrives is out. Everything that can be worked out ahead of time is in.
Output
| Syntax | What it does |
|---|---|
{{ $expr }} |
Prints the value, escaped. Use for all text and attribute values. |
{!! $expr !!} |
Prints the value raw. Only for HTML you trust, such as an inline SVG stored in your data. |
{{-- … --}} |
A comment. Removed entirely; never reaches the browser. |
Directives
| Directive | Notes |
|---|---|
@if (…) @elseif (…) @else @endif |
Conditionals. |
@foreach ($items as $item) @endforeach |
Loops. @foreach ($items as $key => $item) also works. |
@break @continue |
Optionally conditional: @break($loop->iteration == 4). |
@props([…]) |
Declares a component's or layout's accepted values and their defaults. First line of the file. |
@vite(['resources/css/site.css']) |
Links the compiled stylesheet. Goes in the layout's <head>. |
Inside @foreach, $loop exposes exactly seven properties:
| Property | Value |
|---|---|
$loop->index |
Position, counting from 0. |
$loop->iteration |
Position, counting from 1. |
$loop->first |
true on the first pass. |
$loop->last |
true on the last pass. |
$loop->count |
How many entries there are. |
$loop->even |
true on even iterations. |
$loop->odd |
true on odd iterations. |
Expressions
Inside @if, @foreach, @break, and {{ }} you may use:
- Variables —
$site,$services,$title - Property access —
$post->title - Array access —
$items[0] - Comparisons —
==,!=,<,>,<=,>= - Boolean operators —
&&,||,! - Parentheses for grouping
- Literals —
'text',42,true,false - The null-coalescing fallback —
$site->tagline ?? 'Welcome'
Undefined variables are errors. The compiler knows every variable in scope and rejects
anything it does not recognize, which catches typos before a visitor ever sees a blank
space. ?? is the sanctioned way to make a value optional.
Components
| Rule | Detail |
|---|---|
| Location | resources/views/components/… |
| Tag | The path with dots: components/sections/hero.blade.php → <x-sections.hero/> |
| Content | {{ $slot }} inside the component receives whatever the tag wraps. |
| Props | Declared with @props([...]); passed as attributes on the tag. |
| Prop defaults | A scalar, an empty array [], or a flat list. Never keyed, never nested. |
| Scope | A component sees its props, $site, and every collection — not the calling page's variables. |
Files and paths
| Path | Purpose |
|---|---|
resources/views/pages/*.blade.php |
One file per URL. index is /; 404 is the not-found page. |
resources/views/pages/[name.field].blade.php |
A dynamic page: one URL per collection entry. |
resources/views/components/layouts/*.blade.php |
Page shells — the whole HTML document, with {{ $slot }}. |
resources/views/components/sections/*.blade.php |
Reusable page sections. |
resources/data/site.json |
Global site data, read as $site. |
resources/data/collections/*.json |
Data collections, each read as $name. |
resources/data/collections/NAME/*.json |
The same collection as one file per entry, for more than 100 entries — still $NAME, newest first. |
resources/css/site.css |
The stylesheet. |
public/** |
Served verbatim from the root of the website. |
Every template ends in .blade.php. Do not create files at the root of the tree — the
build generates those from your sources and overwrites them.
Not available
These are all real Blade, and all of them need an application running behind the page. Using one produces a report telling you to remove it rather than working output.
| Not available | Instead |
|---|---|
@php |
Move the logic into your JSON data. |
@auth, @guest, @can |
There are no logged-in visitors on a static website. |
@include |
Make it a component and use <x-…/>. |
@extends, @section, @yield |
Layouts are components; wrap the page in <x-layouts.main>. |
@forelse |
@if on the collection, then @foreach. |
@error, @csrf |
Not needed — place a form with @form('slug') and the platform handles submission. See Forms. |
Any function or method call — route('home'), asset(…), count($x), Str::of(…) |
Write the value out, or precompute it in your data. $loop->count covers counting a loop. |
$attributes |
Declare each prop in @props. |
?->, string concatenation with ., assignments, closures, ternaries (? :) |
Use ?? for defaults; do the rest in your data. |
Two related rules that are not directives:
- Link with plain HTML.
<a href="/about">, neveronclick="window.location=…". A clickable card is one<a>wrapping the card's markup, with<span>s inside — never nested<a>elements. - No server-side files.
.php,.py,.rb,.shand friends are refused outright. Blade templates underresources/views/are the exception: they are sources, compiled here and never shipped.
When a template will not compile
Compile problems are reported, not fatal. The build keeps going, so a mistake usually shows up as a section rendering wrong or vanishing rather than as an error page.
The fastest fix is almost always to ask the assistant. It is given the compiler's exact words after every change, so "the services section disappeared after my last edit" is enough for it to find and fix what you cannot see.
If you would rather track it down yourself, these are the usual causes:
| What you see | Usual cause |
|---|---|
| A section vanished | An unclosed @if or @foreach, or a component tag that is not closed. |
| A value prints nothing, or the page reports an unknown variable | A typo in the variable name, a key missing from site.json, or a collection entry missing a key its siblings have. |
| A component renders nothing | The dotted tag does not match the file path — <x-sections.hero/> needs components/sections/hero.blade.php. |
| A message about needing an application | Something from the Not available list is in the template. Remove it. |
| Styling stopped applying | A class name assembled from pieces rather than written out in full, or a token missing from @theme in resources/css/site.css. |
| A link or image is reported as pointing nowhere | The page or file it names does not exist. Create it, or fix the address. |
| A font silently fell back | The family is used in CSS but its <link> is missing from the layout's <head>. |
And if an edit went somewhere you did not intend, the file's History button restores any earlier save — see revision history.
Where to go next
- Building with Blade — the guided tour of the same material.
- Site data and collections — the JSON your templates read.
- Blade in the Laravel documentation — the full language, of which this page is the static subset.