jmf / template-rendering
Simple wrapper around Twig to render templates
1.0.0
2025-04-03 05:23 UTC
Requires
- php: >=8.3
- twig/twig: ^3.20
Requires (Dev)
- phpmd/phpmd: ^2.13
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.0
- rector/rector: ^2.0
- squizlabs/php_codesniffer: ^3.8
README
Simple wrapper around Twig to renderer templates in a single method call.
Usage
Rendering a template from a string
use Jmf\TemplateRendering\TemplateRendererInterface;
/* @var TemplateRendererInterface $renderer */
echo $renderer->renderFromString(
'Hello {{ who }}!',
[
'who' => 'World',
],
);
Will output:
Hello World!
Rendering a template from a file
Given the following Twig template file (named template.twig
):
Hello {{ who }}!
Then:
use Jmf\TemplateRendering\TemplateRendererInterface;
/* @var TemplateRendererInterface $renderer */
echo $renderer->renderFromFile(
'template.twig',
[
'who' => 'World',
],
);
Will output:
Hello World!