PHPackages                             daun/statamic-latte - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. daun/statamic-latte

ActiveStatamic-addon[Templating &amp; Views](/categories/templating)

daun/statamic-latte
===================

Use Latte templates on Statamic sites

2.8.0(2w ago)44971MITPHPPHP ^8.3CI failing

Since Mar 10Pushed 2w ago1 watchersCompare

[ Source](https://github.com/daun/statamic-latte)[ Packagist](https://packagist.org/packages/daun/statamic-latte)[ RSS](/packages/daun-statamic-latte/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (10)Dependencies (25)Versions (26)Used By (0)

Statamic Latte
==============

[](#statamic-latte)

Use the [Latte](https://latte.nette.org/en/) templating language on [Statamic](https://statamic.com/) sites.

Features
--------

[](#features)

- Use Statamic's built-in tags and modifiers
- Resolve the current layout from entry data
- Render Antlers inline where useful
- Use `` for Latte and Blade components

Why Latte?
----------

[](#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 &amp; 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**

```
{{ if entries | count }}

    {{ entries }}
        {{ if link }}
            {{ title }}
        {{ else }}
            {{ title }}
        {{ /if }}
    {{ /entries }}

{{ /if }}
```

**Latte**

```

  link} href={$entry->link}>
    {$entry->title}

```

Installation
------------

[](#installation)

```
composer require daun/statamic-latte
```

Usage
-----

[](#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

[](#tags)

[Statamic Tags](https://statamic.dev/tags) can be used via the native `s:` tag.

```
Found {s:collection:count in:pages /} pages:
```

Unlike Antlers, Latte does not hoist loop item keys into scope. Inside a loop, the item itself is exposed as `$value`. Access fields explicitly with `$value->title` over a bare `{title}`.

```
{s:collection:pages}
  {$value->title}
{/s:collection:pages}
```

Assign tag output using parentheses:

```
{var $entries = (s:collection from: pages, sort: title)}
{foreach $entries as $entry}{$entry->title}{/foreach}
```

Or capture output into a variable using the `as` param:

```
{s:collection from: pages, as: entries}
  {foreach $entries as $entry}{$entry->title}{/foreach}
{/s:collection}
```

Use self-closing tags to output simple scalar return values from tags:

```
{s:link to: "snacks"/}
```

#### Arguments

[](#arguments)

Nested parameters are supported, with either `=>` or `:` separators. They accept variables, literals and expressions.

```
{var $entries = (s:collection from: pages, status:is => draft)}
{var $entries = (s:collection from: pages, title:contains:Christmas)}
{var $entries = (s:collection from: pages, title:contains:$request->title)}
```

#### Pagination

[](#pagination)

Paginated tags return a Laravel paginator. Loop it directly and fetch meta from its built-in methods.

```
{s:collection:pages as: entries, paginate: 10}
  {foreach $entries as $entry}{$entry->title}{/foreach}
  Page {$entries->currentPage()} of {$entries->lastPage()}
{/s:collection:pages}
```

#### Subexpressions

[](#subexpressions)

Wrap a tag in parentheses to use it inline as a plain expression — in `{var}`, conditions, filters, `foreach`, and Latte's `n:` attributes:

```
{var $entries = (s:collection from: pages, sort: title)}
{if (s:collection:count in: pages) > 1}many{/if}
{(s:link to: "snacks")|upper}

{$entry->title}
many
Snacks
```

#### Tags consuming nested content as input

[](#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.

```
{s:widont content: $entry->headline /}
```

### Forms

[](#forms)

Through the proxy, `form:create` returns the form's *data* rather than rendered markup, so you build the `` in Latte and loop the fields yourself. Capture it with `as:`:

```
{s:form:create as: form, in: contact}

        {foreach $form->fields as $field}
            {$field->display}

            {if $field->error}{$field->error}{/if}
        {/foreach}
        Send

{/s:form:create}
```

Check submission state with the scalar `form:success` and the boolean `form:errors` gate:

```
{s:form:success in: contact}{$value}{/s:form:success}

{s:form:errors in: contact}
    Please fix the errors below.
{/s:form:errors}
```

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

[](#modifiers)

[Statamic Modifiers](https://statamic.dev/modifiers) can be used as filters in Latte:

```
{$title|upper|truncate:50}
```

### HTML fields

[](#html-fields)

Latte escapes every printed value, which is what you want for a title and wrong 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:

```
{$entry->title}       {* text field → escaped, even if it holds  *}
{$entry->content}   {* markdown field → …, as markup *}
```

### Resolving values

[](#resolving-values)

Most values are augmented and stringified automatically on print, so you rarely need to unwrap them yourself:

```
{$title}
{$author->name}
```

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:

```
{resolve($author)} or {r($author)}
{$author|resolve}
```

### Mixing Latte and Antlers

[](#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.

```
Rendered in Latte: {$title}

{antlers}
    Rendered in Antlers: {{ title }}
{/antlers}
```

### Layout

[](#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 &amp; Yields

[](#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.

```
{* layout *}

{yield breadcrumbs /}

{* template *}

{section breadcrumbs}
    {$entry->title}
{/section}
```

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:

```
{yield breadcrumbs}
    Homepage
{/yield}
```

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 &amp; Slots

[](#embeds--slots)

Latte composes templates with [`{embed}`](https://latte.nette.org/en/template-inheritance#toc-horizontal-reuse)and [`{block}`](https://latte.nette.org/en/template-inheritance): 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 **exact alias for `{block}`**. It is a pure synonym — same parsing, same rendering — so you can use slot terminology on both sides of an embed:

```
{* partials/figure.latte *}

    {slot caption}Default caption{/slot}

```

```
{* template *}

{embed file 'partials.figure', src: $image->url, alt: $image->alt}
    {slot caption}A custom caption{/slot}
{/embed}
```

Because `{slot}` is identical to `{block}`, 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:

```
{* partials/figure.latte *}

Default caption

{* template *}

{embed file 'partials.figure'}
    A custom caption
{/embed}
```

### Conditional content

[](#conditional-content)

#### Iftext

[](#iftext)

Latte's built-in [`n:ifcontent`](https://latte.nette.org/en/tags#toc-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 `` or a Bard field that rendered nothing but `&nbsp;` 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`:

```
{* dropped: no text, nothing that renders *}

{* kept: text survives stripping *}
Hello
```

Elements that render on their own — images, embeds, form controls — count as content even though they hold no text:

```
{* both kept *}

```

It works as a paired tag too, optionally with `{else}`:

```
{iftext}
    {$page->body}
{else}
    Nothing to show yet.
{/iftext}
```

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

[](#caching)

#### Cache

[](#cache)

Use the `cache` tag to cache parts of a view.

```
{cache for: '10 minutes'}
    {foreach $stocks as $stock}
        {$stock->fetchPrice()}
    {/foreach}
{/cache}
```

#### Nocache

[](#nocache)

The `nocache` tag can be used to exempt part of a view from [static caching](https://statamic.dev/static-caching). Both [caching strategies](https://statamic.dev/static-caching#caching-strategies) are supported.

```
{include 'partials.nav', handle: main}

{nocache}
    {if $logged_in}
        Welcome back, {$user->name}
    {else}
        Hello, Guest!
    {/if}
{/nocache}

{block content}{/block}
```

#### Nesting

[](#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:

```
{cache}
    this will be cached
    {nocache}
        this will remain dynamic
    {/nocache}
    this will also be cached
{/cache}
```

### Components

[](#components)

Latte templates support the `` 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.

```

Go
```

A **Latte component** is a `.latte` template under the `components/` view directory (`` → `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)

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)

[](#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).

```
use Daun\StatamicLatte\Components\Component;

class Alert extends Component
{
    public function __construct(
        public string $type = 'info',
    ) {}

    public function data(): array
    {
        return [...parent::data(), 'classes' => "alert alert-{$this->type}"];
    }
}
```

#### Slots

[](#slots)

**Latte components** use named and default slots, which compile to `{embed}` blocks. Fill a named slot with `` (or ``); 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.

```
{* components/alert.latte *}

    {slot title}Notice{/slot}
    {slot default}{/slot}

{* usage *}

    Heads up
    Something happened.

```

**Blade components** accept a body as the default slot (`{{ $slot }}`), captured as a pre-rendered string and echoed directly. Named slots work too: each `` becomes a Blade `ComponentSlot` (`$name`, with `isEmpty()`/`isNotEmpty()` and its own `$name->attributes`).

```

    Hello World

    Heads up
    Body content

```

#### Control attributes

[](#control-attributes)

Latte's `n:` control attributes work on components:

```
content

```

License
-------

[](#license)

[MIT](https://opensource.org/licenses/MIT)

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance96

Actively maintained with recent releases

Popularity21

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~45 days

Recently: every ~3 days

Total

20

Last Release

19d ago

Major Versions

1.3.0 → 2.0.02026-06-14

PHP version history (2 changes)1.0.0PHP ^8.1

2.0.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/31ac2b3787ded290b6bac87b937abf4f267483e4da64731bfb256a942bb669ca?d=identicon)[daun](/maintainers/daun)

---

Top Contributors

[![daun](https://avatars.githubusercontent.com/u/22225348?v=4)](https://github.com/daun "daun (208 commits)")

---

Tags

lattestatamicstatamic-addontemplatesviewsnetteviewlattestatamic

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/daun-statamic-latte/health.svg)

```
[![Health](https://phpackages.com/badges/daun-statamic-latte/health.svg)](https://phpackages.com/packages/daun-statamic-latte)
```

###  Alternatives

[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

137236.2k8](/packages/statamic-rad-pack-runway)[duncanmcclean/statamic-cargo

Comprehensive e-commerce addon for Statamic. Build bespoke e-commerce sites without the complexity.

3622.8k](/packages/duncanmcclean-statamic-cargo)[statamic/statamic

Statamic

832182.1k](/packages/statamic-statamic)[statamic/cms

The Statamic CMS Core Package

4.9k3.8M1.2k](/packages/statamic-cms)[aerni/advanced-seo

Comprehensive SEO addon for Statamic with flexibility in mind

1818.9k](/packages/aerni-advanced-seo)[marcorieser/statamic-livewire

A Laravel Livewire integration for Statamic.

23122.2k16](/packages/marcorieser-statamic-livewire)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
