Download the PHP package bugo/antlers-php without Composer
On this page you can find all versions of the php package bugo/antlers-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package antlers-php
Antlers PHP
A standalone implementation of the Antlers templating engine, designed for use outside the Statamic/Laravel ecosystem in any PHP 8.2+ project.
По-русски
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
Quick Start
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:
Treat plain {{ ... }} output as raw template output unless you have applied the escaping yourself.
Syntax
Variables
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
Arithmetic and Strings
Conditions
Loops
Variables available inside loops include:
| Variable | Description |
|---|---|
{{ 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 item |
Paired array loops also support neighbor access via colon notation:
Modifiers
Setting Variables
Comments
{{? ?}} and {{$ $}} are not available in this engine. If you need PHP, keep it outside Antlers templates in your application code.
Noparse
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
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.
| Status | Modifiers |
|---|---|
| Supported 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
antlers, partial, and raw are intentionally excluded from the standalone modifier API.
partialstays a tag concern in this project: usepartial,partial:exists, andpartial:if_existsinstead of a modifier.antlersis not part of the first stable standalone core because re-rendering strings as templates needs a separate execution model and explicit recursion safeguards.rawis not included becauseantlers-phpdoes not auto-escape output by default; literal/raw behavior is already covered by normal output,@{{ ... }}, andnoparse.
String
| Modifier | Description | Example | |----------|-------------|---------| | `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
| Modifier | Description | Example | |----------|-------------|---------| | `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
| Modifier | Description | Example | |----------|-------------|---------| | `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
| Modifier | Description | Example | |----------|-------------|---------| | `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
| Modifier | Description | Example | |----------|-------------|---------| | `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
Custom Modifier
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:
Paired Tag with Children
Global Variables
Strict Mode
All versions of antlers-php with dependencies
symfony/string Version ^7.4|^8.0
symfony/translation-contracts Version ^3.6