php-text-template
A simple template engine.
A small standalone PHP library for filling placeholder variables into text templates at runtime, useful for generating emails, config files, or any structured text where the layout stays fixed but values change.
This is a small PHP library that provides a simple text template engine. A template engine lets you define a block of text with placeholder variables in it, then fill in those placeholders with actual values at runtime to produce the final output. This is useful for generating things like email bodies, code files, configuration files, or any structured text where the layout stays the same but certain values change each time it is used.
The library is part of the PHPUnit ecosystem, maintained by Sebastian Bergmann, who also maintains the PHPUnit testing framework for PHP. It is used internally by PHPUnit to generate code and output, but it is published as a standalone package so any PHP project can use it independently without pulling in PHPUnit itself.
Installing it requires Composer, the standard PHP package manager. One command adds it as a project dependency. If the library is only needed during development, such as for generating test output or boilerplate code, it can be added as a development-only dependency instead, which keeps it out of production builds.
The README is short and does not include usage examples or a description of the template syntax. For details on how to use it, you would need to look at the source code directly or find examples in the PHPUnit codebase. The library is available on Packagist, the public PHP package registry, under the name phpunit/php-text-template.
Where it fits
- Generate personalised email bodies by defining a template with placeholders and substituting recipient-specific values at send time
- Produce configuration files or code boilerplate from templates where only certain values differ per output