1. Go to this page and download the library: Download performing/twig-components 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/ */
// TwigEnvironmentConfigurator.php
use Symfony\Bundle\TwigBundle\DependencyInjection\Configurator\EnvironmentConfigurator;
use Twig\Environment;
use Performing\TwigComponents\Configuration;
final class TwigEnvironmentConfigurator
{
public function __construct(
private EnvironmentConfigurator $decorated
) {}
public function configure(Environment $environment) : void
{
$this->decorated->configure($environment);
// Relative path to your components folder
$relativePath = '_components';
Configuration::make($environment)
->setTemplatesPath($relativePath)
->setTemplatesExtension('twig')
->useCustomTags()
->setup();
}
}
public function boot(): void
{
Event::Listen('cms.page.beforeDisplay', function ($controller, $url, $page) {
$twig = $controller->getTwig();
Configuration::make($twig)
->setTemplatesPath('namespace.pluginname::components', hint: true)
->useCustomTags()
->useGlobalContext() // use this to keep twig context from cms
->setup();
});
}