PHP code example of xervice / twig

1. Go to this page and download the library: Download xervice/twig library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xervice / twig example snippets




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');
    }
}



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()
        ];
    }
}

$params = [];
$twigFacade->render('mytemplate.twig', $params);