1. Go to this page and download the library: Download havit/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/ */
use Pimple\{Container, ServiceProviderInterface};
class TwigComponentsServiceProvider implements ServiceProviderInterface
{
public function register(Container $app)
{
$app->extend('twig', function (\Twig_Environment $twig, $app) {
$twig->addExtension(new \Havit\TwigComponents\Extension\ComponentExtension($twig));
$twig->setLexer(new \Havit\TwigComponents\Lexer\ComponentLexer($twig));
return $twig;
});
}
}
namespace App\View;
use App\Application;
class Test extends \Havit\TwigComponents\View\Component
{
public $title = '';
public function __construct(string $title = 'xyz')
{
$this->title = $title;
}
public function handle(Application $app)
{
// Do something
$this->title = $app->trans($this->title);
}
public function template(): string
{
return 'components/test.twig';
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.