Download the PHP package daun/statamic-latte without Composer
On this page you can find all versions of the php package daun/statamic-latte. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package statamic-latte
Statamic Latte
Use the Latte templating language on Statamic sites.
Features
- Use Statamic's built-in tags and modifiers
- Resolve the current layout from entry data
- Render Antlers inline where useful
- Use
<x-component>for Latte and Blade components
Why Latte?
Latte is simple, safe, and fast. Templates are compiled. Expressions are plain PHP. Output values are escaped automatically, in every context. Latte adds concise inline control structures and smart attributes for expressive templating.
- PHP syntax, no new language: Expressions and conditions are plain PHP, so there's little mental context-switching between template and application code.
- Context-aware escaping: Latte understands HTML and escapes differently inside text, attributes, JavaScript or URLs.
- Concise & expressive: Control flow lives directly on the html elements, clarifying intent and reducing nesting.
- Smart html attributes: Booleans,
null, arrays and data attributes render correctly with no manual string juggling, similar to modern frontend frameworks. - Fast: Templates compile to PHP once and run as native code on every request.
Antlers
Latte
Installation
To change any of the addon's settings, publish its config file:
Usage
Once installed, you can use Latte views in your frontend. Save or rename your views
using the extension .latte and reference them as usual. Antlers and Latte views can live
side-by-side as long as view names are unique.
Tags
Statamic Tags can be used via the native s: tag.
Unlike Antlers, Latte does not hoist loop item keys into scope. The canonical pattern in Latte is to capture the tag output in a variable and loop over that directly. You can do that by using parentheses to wrap any tag:
Or capture output into a variable using the as param:
Arguments
Nested parameters are supported, with either => or : separators. They accept
variables, literals and expressions.
Pagination
Paginated tags return a Laravel paginator. Loop it directly and fetch meta from its built-in methods.
Subexpressions
Wrap a tag in parentheses to use it inline as a plain expression — in {var}, conditions,
filters, foreach, and Latte's n: attributes:
Tags consuming nested content as input
Some tags transform their tag-pair body instead of returning data (e.g. widont,
obfuscate ). Hand it to the tag via the content: argument.
Forms
In Latte, form:create returns the form object rather than rendered markup,
so you build the <form> in Latte and loop the fields yourself. Capture
it with as::
Check submission state with the scalar form:success and the boolean
form:errors gate:
To list individual error messages, read them from the form:create capture
($form->errors, or $form->error->{handle} for a field's first error) — the
form:errors pair is a boolean gate here, not an iterator.
Modifiers
Statamic Modifiers can be used as filters in Latte:
HTML fields
Latte properly escapes every printed value, which is what you want for a title but not for
a markdown field. Fields whose fieldtype renders HTML during augmentation — bard,
markdown, redactor — are recognized and printed as markup, so |noescape is not
needed:
Resolving values
Most values are augmented and stringified automatically on print, so you rarely need to unwrap them yourself:
As an escape hatch for the cases where you hold a raw Value/LabeledValue object (e.g. when
passing one into a function or comparison), the resolve and r helpers and filter return the
underlying value:
Mixing Latte and Antlers
If you ever need to combine Latte and Antlers code, you can use the antlers tag in your
Latte views to render Antlers code inline. This can be useful for complex built-in tags or quick
prototyping by copy-pasting examples from the docs.
Layout
Just like in Antlers templates, the correct layout file will be used based on the data available in your entries and blueprints.
By default, it will look for /resources/views/layout.latte, but you can configure specific entries
and collections to use different layouts instead by setting layout: other_layout on the entry or
collection config file.
Sections & Yields
Use the section and yield tags to define content in one place and output it in
another. They map directly to Antlers' identical tags.
Use the self-closing form {yield 'name' /} when there's no fallback. To provide
default content for when no section was defined, use the paired form:
Sections and yields share Statamic's underlying content store, so they interoperate freely across Latte, Antlers and Blade templates: a section defined in an Antlers partial can be yielded in a Latte layout, and vice versa.
Embeds & Slots
Latte composes templates with {embed}
and {block}: a partial defines
named, fillable regions with {block}, and the embedding template overrides them
inside {embed}.
For parity with the component/slot vocabulary used by Antlers and Blade, {slot} is
provided as an alias for {block}, so you can use slot terminology on both sides of an embed:
{slot} behaves exactly like {block}, so the two are interchangeable everywhere
(including layouts and {extends}) and you can freely mix them. Omitting a slot in the
embed falls back to the default content defined in the partial.
The n:slot attribute is also available (mirroring n:block) and works on both sides:
Scoped slots
Slot content sees two sets of variables, much like scoped slots in Vue or snippets in Svelte:
- the caller's variables at the
{embed}site, including{var}locals - the partial's variables at the point where it renders the slot, e.g. the current loop item
That lets a partial render a slot once per item in a loop while the caller decides what each item looks like:
The filled slot replaces the inline default for every row; without a fill, the default renders for every row. If a name exists on both sides, the partial's value wins.
To give a slot an explicit interface instead of exposing the whole loop scope, define it with
parameters and render it with {include}:
The caller fills it the same way, with {slot row}…{$cell}…{/slot}.
Conditional content
Iftext
Latte's built-in n:ifcontent omits an element when
it renders no output at all. Empty markup still counts as output, though, so a wrapper around an empty
<p> or a Bard field that rendered nothing but <p> </p> survives.
The iftext tag tests for visible content instead. Tags are stripped from the rendered output before
the emptiness check — think innerText where n:ifcontent is innerHTML:
Elements that render on their own — images, embeds, form controls — count as content even though they hold no text:
It works as a paired tag too, optionally with {else}:
The elements that count as content on their own are img, picture, svg, video, audio,
iframe, embed, object, canvas, script, hr, table, form, input, button, select,
textarea, progress and meter. Adjust the list in a service provider if your markup needs it:
Caching
Cache
Use the cache tag to cache parts of a view.
Nocache
The nocache tag can be used to exempt part of a view from static caching.
Both caching strategies are supported.
Nesting
The cache and nocache tags can be nested in either direction. A nocache region inside a
cache block stays dynamic even when the surrounding fragment is served from cache:
Components
Latte templates support the <x-component> syntax. A single tag resolves at compile time to either
a Latte or a Blade component. In case of a conflict, the Latte template wins.
A Latte component is a .latte template under the components/ view directory
(<x-forms.button> → components/forms/button.latte). Its tag is desugared to a native
{embed}, so the template receives the attributes as variables and renders slots as blocks.
Anything without a matching template falls back to a Blade component (class, anonymous or
vendor), rendered at runtime.
Attributes
Attributes can be static strings, dynamic PHP expressions, or bare booleans. For Latte
components they become variables in the template; for Blade components, any attributes not
declared as constructor params flow into the $attributes bag.
Backing class (optional)
A Latte component may have a backing class extending Daun\StatamicLatte\Components\Component
for logic. Constructor parameters are filled from the tag's attributes, and data() is spread
into the template's variables. Without a class, a component is just its template (anonymous).
Slots
Latte components use named and default slots, which compile to {embed} blocks. Fill a named
slot with <x-slot:name> (or <x-slot name="name">); the remaining body fills the default slot.
A slot that is omitted falls back to the {slot …} content defined in the component template, and
slot content is evaluated in the caller's scope.
Blade components accept a body as the default slot ({{ $slot }}), captured as a pre-rendered
string and echoed directly. Named slots work too: each <x-slot:name> becomes a Blade
ComponentSlot ($name, with isEmpty()/isNotEmpty() and its own $name->attributes).
Control attributes
Latte's n: control attributes work on components:
Cascade variables
Latte views receive the page through $page only; its fields are not repeated as variables.
This differs from Antlers, where all page fields are available as variables.
To get Statamic's own behaviour back, set cascade to full in config/statamic-latte.php: