Common interface to manipulate strings/data with any transformer. Great for use in templating libraries, static site generators, web frameworks, and more. Inspired by JSTransformers.
To use each of these transformers, you will also need to composer require
them in your project.
- Twig (From SensioLabs/Symfony)
- Smarty
- Mustache
- Latte (From Nette Framework)
- StringTemplate
- Plates (From The PHP League)
- Dwoo
- Blade (From Laravel Framework)
- PHPTAL
- Text-Template (From PHPUnit)
Via Composer
$ composer require phptransformers/phptransformer
// With "phptransfomers/twig" package
$transformer = new PhpTransformers\Twig\TwigTransformer();
echo $transformer->render('Hello, {{ name }}!', array(
'name' => 'World'
));
//=> Hello, World!
Before all examples, you will need to load a transformer:
$transformer = new PhpTransformers\Twig\TwigTransformer();
$transformer = new PhpTransformers\Smarty\SmartyTransformer();
// ... same thing for all other Transformers
See each transformers' repository for more details
Renders the given template string, using the provides locals for options passed in. Returns the result as a string.
$locals = array('name' => 'World');
$output = $transformer->render('Hello, {{ name }}!', $locals);
Renders the given file, using the provided locals for options passed in. Returns the result as a string.
$locals = array('name' => 'World');
$output = $transformer->renderFile('hello.twig', $locals);
$ composer test
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.