.lex template files into cached PHP files through a multi-stage pipeline, and works with any PHP project — no framework required.
How it works
Every.lex template you write passes through five sequential stages before it reaches the browser:
render() call. In production mode all source I/O is skipped and templates are served directly from a precompiled index — zero recompilation per request.
Key features
Layout inheritance
Compose pages from reusable layouts using
#extends, #section, #yield, and #parent. Push content into named stacks with #push / #stack.Components
Use PascalCase tags as self-contained components with named slots, dynamic props (
:prop="$expr"), and optional PHP class mounting via mount().Dependency graph cache
Lex records every
#extends, #include, and component dependency at compile time. When a shared partial changes, every template that depends on it is automatically invalidated and recompiled on the next request.Sandbox mode
Restrict what template authors can do with an expression whitelist, raw-echo control, and 50+ always-blocked functions (
eval, exec, system, and more). Useful for user-submitted templates.CLI (`bin/lex`)
A command-line tool is registered at
bin/lex after installation. Use it to warm up the template cache before deployment or to initialise a new lex.config.json.Chrome DevTools extension
In development mode every
render() call injects a JSON debug payload. The Lex DevTools Chrome extension surfaces a component tree, section inspector, cache viewer, error overlay with “Open in VS Code”, and a render-time timeline.Requirements
| PHP | ^8.1 |
| Extensions | mbstring (recommended), igbinary (optional — faster AST cache serialisation) |
| Dependencies | phpunit/phpunit, psr/http-server-middleware |
The
igbinary extension is entirely optional. When present, Lex uses it for faster AST snapshot serialisation in .lexer/ast/. Without it, standard PHP serialisation is used automatically.Installation
Install via Composer and set up
lex.config.json for your project.Quick Start
Render your first template in minutes using the config-file or fluent API.