This bundle integrates the PHP templates library into Symfony.
$ composer require setono/php-templates-bundleIf you use Symfony Flex it will be enabled automatically. Else you need to add it to the config/bundles.php:
<?php
// config/bundles.php
return [
// ...
Setono\PhpTemplatesBundle\SetonoPhpTemplatesBundle::class => ['all' => true],
// ...
];The bundle registers the service setono_php_templates.engine.default and also autowires the interface
Setono\PhpTemplates\Engine\EngineInterface to that default engine. This means you can inject the engine just by
type hinting the interface:
<?php
use Setono\PhpTemplates\Engine\EngineInterface;
final class YourService
{
/** @var EngineInterface */
private $engine;
public function __construct(EngineInterface $engine) {
$this->engine = $engine;
}
public function __invoke(): string
{
return $this->engine->render('YourNamespace/template', [
'parameter' => 'value'
]);
}
}The bundle automatically adds paths to the template engine. It is predefined to src/Resources/views/php for bundles
and templates/php for applications.
This means if you put templates (according the correct structure) you can use templates seamlessly as described in the original docs.