Twig Template Renderer for Antidot Framework
Via Composer
$ composer require antidot-fw/twig-template-renderer
It will work out of the box, the only thing you need is to inject the TemplateRenderer interface in your request handler constructor
See factory classes at src/Container
.
<?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,
],
],
];
See full Twig documentation for more detail.
<?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',
])
);
}
}
Please see CHANGELOG for more information on what has changed recently.
$ composer test
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
If you discover any security related issues, please email kpicaza@example.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.