A lightweight, regex based template rendering engine for PHP
Templex lets you define stubs and hydrate them using PHP variables. The engine uses regex for all processing — no eval(), no including and running code as PHP. This means you can safely generate new PHP files, config files, or any text-based content from templates.
- PHP 8.5 or higher
composer require myerscode/templexuse Myerscode\Templex\Templex;
$templex = new Templex(__DIR__ . '/templates/', 'stub');
echo $templex->render('welcome', ['name' => 'Fred']);Where templates/welcome.stub contains:
Hello <{ $name }>!
- Templates — template syntax, file types, and configuration
- Slots — includes, conditions, loops, switch statements, and variables
Bug reports and feature requests can be submitted on the Github Issue Tracker.
Contributions are welcome! Please see contributing.md for guidelines on how to contribute to this project.
The MIT License (MIT). Please see License File for more information.