Phrender is a simplistic PHP renderer that provides a no frills rendering engine.
PSR-1 and PSR-4 compliant.
This uses the Output Interop specification.
The following contexts are provided for use:
- Collection Any number of the following
- Any Matches any template
- Contains uses
stripos
to match the template - Match Uses a regex to match the template
- Only Will match only the specified template
Phrender can be installed using composer
composer require dlundgren/phrender
<?php
$factory = new Phrender\Template\Factory(['/path/to/views']);
$engine = new Phrender\Engine($factory, new Phrender\Context\Collection());
// index.php: <?= $this->var ?>
// output = "something"
$output = $engine->render('index', ['var' => 'something']);
// Alternate
// output = ""
$ctxt = new Phrender\Context\Contains('something', ['var' => 'display']);
$output = $engine->render('index', $ctxt);
You may use an alternate extension for the templates with the Template Factory constructor second argument.
$factory = new Phrender\Template\Factory(['/path/to/views'], 'phtml');
$engine = new Phrender\Engine($factory, new Phrender\Context\Collection());
// index.phtml: <?= $this->var ?>
// output = "something"
$output = $engine->render('index', ['var' => 'something']);