- PHP 8.2+
- Minimal deps
- Sandboxed
- OPcache
Clarity Engine
A fast, secure, and expressive PHP template engine – Maximum performance, whether sandboxed and secure or with the full power of PHP.
Why Clarity
Compiled, cached, contained
Compiled & Cached
Templates compile to PHP classes and ride the OPcache for blazing-fast rendering. First render compiles, every render after is straight PHP.
Secure Sandbox
No arbitrary PHP execution. Templates can only access variables passed to render() and registered filters — nothing else gets through.
Expressive Syntax
Clean, readable template language with macros, template inheritance, the filter pipeline and context-aware auto escaping. Familiar, fast, and easy to learn.
Modules & Extensions
Bundle filters, functions and directives into self-registering plug-ins. Register custom filters, functions, inline filters and block directives without touching the engine.
Unicode Aware
Full multibyte string handling with transparent normalization, auto-escaping that understands context, and clean integration with PHP's intl extension.
Minimal Dependencies
Standalone engine with no external dependencies beyond PHP 8.2+ and mbstring. Just composer require and start rendering.
From zero to rendered
Build your first Clarity template in under a minute. Templates extend a layout, render variables, and call the filter pipeline — all without leaving the sandbox.
-
One-liner
composer require - Compiled to PHP classes for OPcache-friendly rendering
-
Auto-escaping with
{{ "…" |> raw }}opt-out - Built-in macros, inheritance, includes and filter chains
<?php
use Clarity\ClarityEngine;
$engine = new ClarityEngine([
'viewPath' => __DIR__ . '/views',
'namespaces' => [
'admin' => __DIR__ . '/views/admin',
'emails' => __DIR__ . '/views/emails',
],
]);
echo $engine->render('welcome', [
'title' => 'Welcome to Clarity',
'user' => ['name' => 'Developer'],
]);
Syntax
Reads like HTML, renders like PHP
Clarity's syntax is intentionally close to modern template engines so existing skills transfer cleanly. Variables, filters, control flow, macros and layout inheritance — all available, all sandboxed.
{% extends "layouts/base" %}
{% block content %}
<h1>Hello, {{ user:name }}!</h1>
<p>{{ post:date |> date("M j") }}</p>
{% macro card(title, body) %}
<div class="card">
<h3>{{ title }}</h3>
<p>{{ body }}</p>
</div>
{% endmacro %}
{% call card("Welcome back", intro) %}
{% endblock %}
<h1>Hello, Developer!</h1>
<p>Nov 8</p>
<div class="card">
<h3>Welcome back</h3>
<p>The sandbox is warm.</p>
</div>
- Filter chains
- Macros & calls
- Loops & conditions
- Spread literals
Measured, not claimed
Benchmark results
Seven engines render the same page from the same template and the same data: a layout, an included partial, a block of flat values each emitted twice — once as text, once in an attribute — and a table of rows with six fields each, with every value HTML-special so the escaping path does real work in both contexts. Each engine renders in-process, so a difference here is the engine rather than the server, and inside every chart each row is relative to the fastest.
Time per render steady state
Every render of the same page is measured: the dot is the median, the caps the fastest observation and the 95th percentile.
First render cold template cache
The first request after a deploy: engine classes load, the template compiles, the cache is written and the page renders once.
Memory per run retained heap
The heap a whole run still holds after a garbage collection, and the run's high-water mark, each read in its own fresh process.
Median of 10,000 renders per run over 30 runs, 200 items per render, rendered in-process on the PHP CLI. PHP 8.5.11 · OPcache (opcache.enable_cli): yes · JIT: tracing (buffer 64M) · Clarity template revalidate: 60 s.
Dig in
Explore the Engine
Documentation
Template Syntax, Filters & Functions, Layout Inheritance, Modules, Best Practices and Troubleshooting — everything in one place.
Read the docsAPI Reference
Auto-generated reference for every public class — engine, compiler, tokenizer, modules, localization and loaders.
Browse the APISource on GitHub
Browse the engine source, file issues, or read the release notes on the Sailantis organisation.
Open the repositoryInstall
One command, no dependencies
Requires PHP 8.2+ with the mbstring extension. The
intl extension enables locale-aware formatting.
composer require sailantis/clarity-engine
Or read the docs first.