1. Go to this page and download the library: Download sympress/twig-bundle 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/ */
sympress / twig-bundle example snippets
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
final class ShopTwigExtension extends AbstractExtension
{
public function getFunctions(): array
{
return [
new TwigFunction('shop_name', fn (): string => 'SymPress'),
];
}
}
use Twig\Attribute\AsTwigFunction;
final class ShopTwigRuntime
{
#[AsTwigFunction('shop_name')]
public function shopName(): string
{
return 'SymPress';
}
}
use SymPress\TwigBundle\Extension\GlobalProviderInterface;
final class AppGlobals implements GlobalProviderInterface
{
public function getGlobals(): iterable
{
return [
'app_name' => 'SymPress',
];
}
}
use SymPress\TwigBundle\Attribute\AsTwigGlobal;
#[AsTwigGlobal('current_account')]
final class CurrentAccount
{
}
use SymPress\TwigBundle\Renderer\TemplateRendererInterface;
final readonly class PageRenderer
{
public function __construct(
private TemplateRendererInterface $templates,
) {
}
public function render(): string
{
return $this->templates->render('page.html.twig', [
'title' => 'Hello SymPress',
]);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.