, (*1)
Twig template engine implementation for xervice., (*2)
Installation
composer require xervice/twig
Configuration
To define twig paths, where to search for templates, you can share a PathProvider:, (*3)
<?php
namespace App\Application\Communication\Plugin\Twig;
use Xervice\Twig\Business\Model\Loader\XerviceLoaderInterface;
use Xervice\Twig\Business\Dependency\Path\PathProviderInterface;
class PathLoader implements PathProviderInterface
{
/**
* @param \Xervice\Twig\Business\Loader\XerviceLoaderInterface $loader
*
* @throws \Twig_Error_Loader
*/
public function privideTwigPaths(XerviceLoaderInterface $loader): void
{
$loader->addPath('path/to/my/twig-templates', 'Application');
}
}
You can register your PathLoader in the TwigDependencyProvider:, (*4)
<?php
namespace App\Twig;
use App\Application\Communication\Plugin\Twig\PathLoader;
use Xervice\Twig\TwigDependencyProvider as XerviceTwigDependencyProvider;
class TwigDependencyProvider extends XerviceTwigDependencyProvider
{
/**
* @return \Xervice\Twig\Business\Dependency\Path\PathProviderInterface[]
*/
protected function getPathProviderList(): array
{
return [
new PathLoader()
];
}
}
Usage
You can render templates by using the TwigFacade:, (*5)
$params = [];
$twigFacade->render('mytemplate.twig', $params);
Also you can provide the TwigService to your Kernel stack and use them in your controller. The service provide the same register-method., (*6)