dlundgren / phrender
Simple PHP Renderer
Installs: 129
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/dlundgren/phrender
Requires
- php: >=8.1
- output-interop/output-interop: ^0.2.0
Requires (Dev)
- phpstan/phpstan: ^2.1.22
- phpunit/phpunit: >=10
- squizlabs/php_codesniffer: ^3.4.2
- syberisle/coding-standards: ^2.0
README
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.
Contexts
The following contexts are provided for use:
- Collection Any number of the following
- Any Matches any template
- Contains uses
stripos
to match the template - Matches Uses a regex to match the template
- Only Will match only the specified template
Installation
Phrender can be installed using composer
composer require dlundgren/phrender
Basic Usage
<?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);
Different extension
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']);