PHPackages                             bugo/antlers-php - 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. bugo/antlers-php

ActiveLibrary[Templating &amp; Views](/categories/templating)

bugo/antlers-php
================

Standalone Antlers template engine — use outside Statamic/Laravel

0.1(1mo ago)00MITPHPPHP ^8.2CI passing

Since May 2Pushed 1mo agoCompare

[ Source](https://github.com/dragomano/antlers-php)[ Packagist](https://packagist.org/packages/bugo/antlers-php)[ RSS](/packages/bugo-antlers-php/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (7)Versions (2)Used By (0)

Antlers PHP
===========

[](#antlers-php)

[![PHP](https://camo.githubusercontent.com/7bffcab80be9e1d83d7ec1e72f01342ea9ea17a26347f9b34a8d4a5ae8b58c48/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253545382e322d626c75652e7376673f7374796c653d666c6174)](https://camo.githubusercontent.com/7bffcab80be9e1d83d7ec1e72f01342ea9ea17a26347f9b34a8d4a5ae8b58c48/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253545382e322d626c75652e7376673f7374796c653d666c6174)[![Coverage Status](https://camo.githubusercontent.com/e5316d4a43f4a009998aa5fc9b55ac93e5f0136d969ee200de7fb7070e273230/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f647261676f6d616e6f2f616e746c6572732d7068702f62616467652e7376673f6272616e63683d6d61696e)](https://coveralls.io/github/dragomano/antlers-php?branch=main)

A standalone implementation of the [Antlers](https://statamic.dev/frontend/antlers) templating engine, designed for use outside the Statamic/Laravel ecosystem in any PHP 8.2+ project.

[По-русски](README.ru.md)

Positioning
-----------

[](#positioning)

`antlers-php` targets a standalone Antlers subset for regular PHP projects.

This means the project aims to support the core Antlers language that works predictably without Statamic or Laravel, such as variables, expressions, conditions, loops, modifiers, partials, and custom tags/modifiers.

It does not promise full compatibility with every Statamic tag, modifier, CMS feature, or Laravel-dependent integration.

In particular, `{{? ?}}` and `{{$ $}}` PHP delimiters from Statamic Antlers are intentionally not supported in `antlers-php`. This project keeps PHP execution out of the standalone core instead of exposing it as a template feature.

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

[](#installation)

```
composer require bugo/antlers-php
```

Quick Start
-----------

[](#quick-start)

```
use Bugo\Antlers\Engine;

$engine = new Engine();

echo $engine->render('Hello, {{ name }}!', ['name' => 'World']);
// → Hello, World!
```

Security
--------

[](#security)

`antlers-php` does not auto-escape `{{ ... }}` output by default. This is intentional for standalone Antlers compatibility.

When rendering user-provided content into HTML, explicitly escape it with `sanitize` or `entities`:

```
{{ comment | sanitize }}
{{ email | entities }}
```

Treat plain `{{ ... }}` output as raw template output unless you have applied the escaping yourself.

Syntax
------

[](#syntax)

### Variables

[](#variables)

```
{{ name }}
{{ user.profile.name }}
{{ items[0] }}
{{ items[key] }}
```

`items[key]` uses the current scope variable `key` as the index. For a literal key, use dot notation: `{{ items.key }}`.

### Null Coalescing and Ternary Operator

[](#null-coalescing-and-ternary-operator)

```
{{ name ?? "Guest" }}
{{ logged_in ? "Welcome back" : "Please log in" }}
```

### Arithmetic and Strings

[](#arithmetic-and-strings)

```
{{ price * 1.2 }}
{{ count + 1 }}
{{ "Hello" . ", " . name . "!" }}
```

### Conditions

[](#conditions)

```
{{ if score > 90 }}
    Excellent!
{{ elseif score > 70 }}
    Good
{{ else }}
    Needs improvement
{{ /if }}

{{ unless logged_in }}
    Log in
{{ /unless }}
```

### Loops

[](#loops)

```
{{# foreach with alias #}}
{{ foreach items as item }}
    {{ item.title }}
{{ /foreach }}

{{# foreach with key and value #}}
{{ foreach data as key => value }}
    {{ key }}: {{ value }}
{{ /foreach }}

{{# statamic-compatible foreach forms #}}
{{ foreach:company_info }}
    {{ key }}: {{ value }}
{{ /foreach:company_info }}

{{ foreach:song_reviews as="song|rating" }}
    {{ song }}: {{ rating }}
{{ /foreach:song_reviews }}

{{ foreach :array="reviews:songs" as="song|rating" }}
    {{ song }}: {{ rating }}
{{ /foreach }}

{{# numeric loop #}}
{{ for 1 to 5 }}
    {{ value }}
{{ /for }}

{{# paired tag that iterates over an array #}}
{{ posts }}
    {{ title }}
{{ /posts }}
```

**Variables available inside loops include:**

VariableDescription`{{ count }}`Current iteration number (starting from 1)`{{ index }}`Current iteration number (starting from 0)`{{ total }}`Total number of items`{{ first }}``true` on the first iteration`{{ last }}``true` on the last iteration`{{ odd }}``true` on odd iterations`{{ even }}``true` on even iterations`{{ key }}`Key of the current itemPaired array loops also support neighbor access via colon notation:

```
{{ songs }}
    {{ value }} (next: {{ next:value }}, prev: {{ prev:value }})
{{ /songs }}
```

### Modifiers

[](#modifiers)

```
{{ title | upper }}
{{ title | lower | truncate:50 }}
{{ price | multiply:1.2 | round:2 }}
{{ items | sort | first }}
{{ date | format:"d.m.Y" }}
```

### Setting Variables

[](#setting-variables)

```
{{ set greeting = "Hello" }}
{{ greeting }}, {{ name }}!
```

### Comments

[](#comments)

```
{{# This text will not appear in the HTML output #}}
```

`{{? ?}}` and `{{$ $}}` are not available in this engine. If you need PHP, keep it outside Antlers templates in your application code.

### Noparse

[](#noparse)

```
{{ noparse }}
    {{ this will not be processed by the engine }}
{{ /noparse }}

Single tag: @{{ name }}
```

### Tags

[](#tags)

```
{{# self-closing tag #}}
{{ greeting name="Alice" }}

{{# tag with method (namespace) #}}
{{ partial:header title="Welcome" }}

{{# paired tag (with content) #}}
{{ markdown }}
**Bold**
{{ /markdown }}
```

Built-in Tags
-------------

[](#built-in-tags)

The standalone core currently registers these built-in tags:

`dump`, `foreach`, `increment`, `layout`, `loop`, `markdown`, `once`, `partial`, `prepend`, `push`, `scope`, `section`, `slot`, `stack`, `svg`, `switch`, `yield`

`set` is also supported as Antlers syntax for variable assignment, but it is language syntax rather than a registered tag from `CoreTags`.

### Core Tag Examples

[](#core-tag-examples)

```
{{ partial src="partials/card.antlers.html" title="Hello" }}
{{ partial:header title="Welcome" }}
{{ partial:exists src="partials/card.antlers.html" }}
{{ partial:if_exists src="partials/maybe.antlers.html" }}

{{ section:hero }}{{ title }}{{ /section:hero }}
{{ yield:hero }}
{{ yield:sidebar }}Fallback sidebar{{ /yield:sidebar }}

{{ markdown }}**Bold**{{ /markdown }}
{{ markdown:indent }}
    # Title
{{ /markdown:indent }}

{{ loop times="3" }}{{ value }}{{ /loop }}
{{ loop count="3" start="5" }}{{ value }}{{ /loop }}
{{ loop:2 }}{{ value }}{{ /loop:2 }}

{{ switch between="odd|even" }}
{{ switch name="rows" in="a|b" }}

{{ scope:page }}{{ page:title }}{{ /scope:page }}
{{ dump value=user }}
{{ svg src="icons/logo.svg" }}
{{ increment }}
{{ increment:row from="10" by="5" }}
```

Built-in Modifiers
------------------

[](#built-in-modifiers)

This project intentionally supports an official subset of Statamic modifiers that works well in a standalone PHP engine, without Laravel/Statamic runtime dependencies.

StatusModifiersSupported official subset`add`, `ceil`, `chunk`, `contains`, `count`, `decode`, `divide`, `ends_with`, `entities`, `explode`, `first`, `flatten`, `floor`, `format`, `is_array`, `is_empty`, `is_numeric`, `join`, `kebab`, `keys`, `last`, `lcfirst`, `length`, `limit`, `lower`, `markdown`, `md5`, `mod`, `multiply`, `nl2br`, `pad`, `pluck`, `regex_replace`, `repeat`, `replace`, `reverse`, `round`, `sanitize`, `slugify`, `snake`, `sort`, `starts_with`, `strip_tags`, `studly`, `subtract`, `surround`, `title`, `trim`, `truncate`, `ucfirst`, `unique`, `upper`, `values`, `where`, `word_count`, `wrap`### Disputed Statamic Modifiers

[](#disputed-statamic-modifiers)

`antlers`, `partial`, and `raw` are intentionally excluded from the standalone modifier API.

- `partial` stays a tag concern in this project: use `partial`, `partial:exists`, and `partial:if_exists` instead of a modifier.
- `antlers` is not part of the first stable standalone core because re-rendering strings as templates needs a separate execution model and explicit recursion safeguards.
- `raw` is not included because `antlers-php` does not auto-escape output by default; literal/raw behavior is already covered by normal output, `@{{ ... }}`, and `noparse`.

**String**ModifierDescriptionExample`upper`Uppercase`{{ name | upper }}``lower`Lowercase`{{ name | lower }}``title`Title Case`{{ title | title }}``ucfirst`Capitalize the first character`{{ text | ucfirst }}``lcfirst`Lowercase the first character`{{ text | lcfirst }}``slugify`URL slug`{{ title | slugify }}``snake`snake\_case`{{ name | snake }}``studly`StudlyCase`{{ name | studly }}``kebab`kebab-case`{{ name | kebab }}``trim`Trim whitespace`{{ text | trim }}``truncate`Truncate to N characters`{{ text | truncate:100:"..." }}``limit`Limit length`{{ text | limit:50 }}``word_count`Count words`{{ text | word_count }}``replace`Replace substring`{{ text | replace:"old":"new" }}``regex_replace`Replace using a regex pattern`{{ text | regex_replace:"/old/":"new" }}``nl2br`Line breaks → ```{{ text | nl2br }}``strip_tags`Remove HTML tags`{{ html | strip_tags }}``entities` / `sanitize`Escape HTML`{{ input | entities }}``decode`Decode HTML entities`{{ input | decode }}``markdown`Parse Markdown`{{ content | markdown }}``wrap`Wrap in an HTML tag`{{ text | wrap:"span" }}``surround`Add text before/after`{{ text | surround:"[":"]" }}``repeat`Repeat string`{{ text | repeat:3 }}``starts_with`Starts with`{{ text | starts_with:"Hello" }}``ends_with`Ends with`{{ text | ends_with:"!" }}``contains`Contains substring`{{ text | contains:"word" }}``length`String length`{{ text | length }}`**Numeric**ModifierDescriptionExample`add`Add`{{ price | add:10 }}``subtract`Subtract`{{ price | subtract:5 }}``multiply`Multiply`{{ price | multiply:1.2 }}``divide`Divide`{{ total | divide:100 }}``mod`Modulo`{{ n | mod:2 }}``ceil`Round up`{{ value | ceil }}``floor`Round down`{{ value | floor }}``round`Round`{{ value | round:2 }}`**Array**ModifierDescriptionExample`sort`Sort`{{ items | sort:"name" }}``reverse`Reverse`{{ items | reverse }}``first`First element`{{ items | first }}``last`Last element`{{ items | last }}``pluck`Extract a field`{{ users | pluck:"name" }}``unique`Unique values`{{ tags | unique }}``where`Filter by field`{{ items | where:"status":"active" }}``chunk`Split into groups`{{ items | chunk:3 }}``keys`Array keys`{{ data | keys }}``values`Array values`{{ data | values }}``count`Number of items`{{ items | count }}``join`Join into a string`{{ tags | join:", " }}``explode`Split a string`{{ csv | explode:"," }}`**Date and Time**ModifierDescriptionExample`format`Format a date`{{ date | format:"d.m.Y" }}`Current standalone strategy:

- The built-in date/time surface is intentionally minimal and currently limited to `format`.
- `format` accepts Unix timestamps and strings that PHP can parse via `strtotime()`.
- If parsing fails, the original string is returned unchanged.
- Carbon is intentionally not a dependency of this project.
- Carbon-style or locale-aware modifiers such as `iso_format`, `modify_date`, `days_ago`, `is_today`, or `timezone` are not part of the first stable standalone core.
- If richer date/time support is added later, it should be built on native PHP types such as `DateTimeImmutable`, `DateTimeInterface`, and `DateTimeZone`, preferably as an opt-in extension.

**Utilities**ModifierDescriptionExample`is_empty`Check if empty`{{ items | is_empty }}``is_array`Check if value is an array`{{ items | is_array }}``is_numeric`Check if value is numeric`{{ value | is_numeric }}``md5`MD5 hash`{{ email | md5 }}`Extending
---------

[](#extending)

### Custom Modifier

[](#custom-modifier)

```
// Callable
$engine->addModifier('money', function(mixed $value, array $params, array $context): string {
    $currency = $params[0] ?? 'USD';
    return number_format((float) $value, 2) . ' ' . $currency;
});
// {{ price | money:EUR }}

// Class
use Bugo\Antlers\Modifiers\ModifierInterface;

class ExcerptModifier implements ModifierInterface
{
    public function modify(mixed $value, array $params, array $context): mixed
    {
        $length = (int) ($params[0] ?? 150);
        return mb_substr(strip_tags((string) $value), 0, $length) . '...';
    }
}

$engine->addModifier('excerpt', new ExcerptModifier());
// {{ content | excerpt:200 }}
```

### Custom Tag

[](#custom-tag)

Built-in `cache`/`nocache` are not part of the required standalone core right now. If you need cache-like behavior, you can add it as a custom extension:

```
// Callable
$engine->addTag('icon', function(array $params): string {
    $name = $params['name'] ?? '';
    return "";
});
// {{ icon name="star" }}

// Class with methods (namespace)
use Bugo\Antlers\Tags\AbstractTag;

class CacheTag extends AbstractTag
{
    public function index(): string|array|null
    {
        $key = $this->param('key', 'default');
        // ... cache logic
        return $this->content();
    }

    public function forget(): string|array|null
    {
        $key = $this->param('key', 'default');
        // ... clear cache
        return null;
    }
}

$engine->addTag('cache', new CacheTag());
// {{ cache key="homepage" }}...{{ /cache }}
// {{ cache:forget key="homepage" }}
```

### Paired Tag with Children

[](#paired-tag-with-children)

```
$engine->addTag('repeat', function(array $params, array $data, $processor, $method, $children): string {
    $times  = (int) ($params['times'] ?? 1);
    $output = '';
    for ($i = 0; $i < $times; $i++) {
        $output .= $processor->reduce($children, array_merge($data, ['iteration' => $i + 1]));
    }
    return $output;
});
// {{ repeat times="3" }}{{ iteration }}. Hello!{{ /repeat }}
```

### Global Variables

[](#global-variables)

```
$engine->setGlobals([
    'site_name' => 'My Blog',
    'year'      => date('Y'),
    'user'      => $currentUser,
]);

// Available in all templates without passing them to render()
echo $engine->render('© {{ year }} {{ site_name }}');
```

### Strict Mode

[](#strict-mode)

```
$engine->setStrictMode(true);

echo $engine->render('{{ name }}', ['name' => 'Alice']);
// Alice

echo $engine->render('{{ missing }}');
// throws AntlersRuntimeException
```

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance92

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

39d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6ef0dd570abdd5696bf5ba391bcd00ed0bb0ac5d1a5654785e8f204d548ddfc0?d=identicon)[Bugo](/maintainers/Bugo)

---

Top Contributors

[![dragomano](https://avatars.githubusercontent.com/u/229402?v=4)](https://github.com/dragomano "dragomano (34 commits)")

---

Tags

antlerstemplate-enginetemplateviewengineantlers

###  Code Quality

TestsPest

Static AnalysisPHPStan, Psalm, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/bugo-antlers-php/health.svg)

```
[![Health](https://phpackages.com/badges/bugo-antlers-php/health.svg)](https://phpackages.com/packages/bugo-antlers-php)
```

###  Alternatives

[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.4M195](/packages/sulu-sulu)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6941.5M395](/packages/drupal-core-recommended)[anourvalar/office

Generate documents from existing Excel &amp; Word templates | Export tables to Excel (Grids)

23991.5k](/packages/anourvalar-office)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.4M506](/packages/shopware-core)[jolicode/castor

A lightweight and modern task runner. Automate everything. In PHP.

54642.4k4](/packages/jolicode-castor)

PHPackages © 2026

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