summaryrefslogtreecommitdiff
path: root/src/Template.php
blob: 9c0b0d63526606979840a655694ca98242586460 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php

namespace Elements;

use Twig\Environment;
use Twig\Extension\DebugExtension;
use Twig\Loader\FilesystemLoader;

class Template
{
  public static ?Environment $twig = null;

  public static function init(): void
  {
    $loader = new FilesystemLoader(dirname(__DIR__) . '/templates');
    self::$twig = new Environment($loader, [
      'debug' => true,
    ]);

    self::$twig->addExtension(new DebugExtension());
  }

  public static function render(string $name, array $context = []): string
  {
    return self::$twig->render($name, $context);
  }
}