setono / php-templates-bundle
A Symfony bundle that integrates the php templates library
Installs: 1 168
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 1
Type:symfony-bundle
Requires
- php: ^7.2
- setono/php-templates: ^1.0
- symfony/dependency-injection: ^4.4 || ^5.0
- symfony/framework-bundle: ^4.4 || ^5.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.2
- korbeil/phpstan-generic-rules: ^0.2.4
- matthiasnoback/symfony-dependency-injection-test: ^4.1
- nyholm/symfony-bundle-test: ^1.6
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: ^0.12.23
- phpstan/phpstan-strict-rules: ^0.12.2
- phpunit/phpunit: ^8.5
- roave/security-advisories: dev-master
- sylius-labs/coding-standard: ^3.1
- symplify/coding-standard: ^7.1
- thecodingmachine/phpstan-safe-rule: ^1.0
This package is auto-updated.
Last update: 2024-12-15 22:18:36 UTC
README
This bundle integrates the PHP templates library into Symfony.
Installation
Step 1: Download
$ composer require setono/php-templates-bundle
Step 2: Enable the bundle
If 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], // ... ];
Usage
Service usage
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' ]); } }
Templates
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.