antidot-fw / twig-template-renderer
Antidot Framework Twig template renderer library
Fund package maintenance!
kpicaza
Requires
- php: ^7.4|^8.0
- antidot-fw/template-renderer: ^1.0
- psr/container: ^1.0
- twig/twig: ^3.0
Requires (Dev)
- phpstan/phpstan: ^0.12.25
- phpunit/phpunit: ^9.0
- squizlabs/php_codesniffer: ^3.5
This package is auto-updated.
Last update: 2024-11-30 02:08:20 UTC
README
Twig Template Renderer for Antidot Framework
Install
Via Composer
$ composer require antidot-fw/twig-template-renderer
Antidot framework
It will work out of the box, the only thing you need is to inject the TemplateRenderer interface in your request handler constructor
As standalone component
See factory classes at src/Container
.
Config
<?php declare(strict_types=1); $config = [ 'template' => [ 'debug' => false, 'file_extension' => 'twig', 'charset' => 'utf-8', 'template_path' => 'templates', 'cache' => 'var/cache/twig', 'auto_reload' => false, 'autoescape' => 'html', 'strict_variables' => true, 'globals' => [ // 'name' => 'value', ], 'extensions' => [ // EtensionClassName::class, ], 'filters' => [ // 'name' => PHPCallableClass::class, // 'some_function' => 'php_some_function, ], 'functions' => [ // 'name' => PHPCallableClass::class, // 'some_function' => 'php_some_function, ], ], ];
Usage
See full Twig documentation for more detail.
In a request handler
<?php declare(strict_types=1); use Antidot\Render\TemplateRenderer; use Laminas\Diactoros\Response\HtmlResponse; use Psr\Http\Server\RequestHandlerInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ResponseInterface; class SomeHandler implements RequestHandlerInterface { private TemplateRenderer $template; public function __construct(TemplateRenderer $template) { $this->template = $template; } public function handle(ServerRequestInterface $request) : ResponseInterface { return new HtmlResponse( $this->template->render('index.html', [ 'name' => 'Koldo ;-D', ]) ); } }
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email kpicaza@example.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.