I have 2 classes, first is controller and second one is the class that load Twig.
This is working fine, but i'm curious if i can do it like this: echo $twig->render('index.html');
Maybe different solution to load Twig in controller?
Twig class taken from: Include twig loader from external file
Home.php
<?php
namespace Controllers;
use Helpers\Twig;
class Home {
public static function index()
{
echo Twig::$twig->render('index.html');
}
}
?>
Twig.php
<?php
namespace Helpers;
class Twig {
public static $twig;
public static function init() {
$loader = new \Twig_Loader_Filesystem(__DIR__.'/../views');
self::$twig = new \Twig_Environment($loader);
}
}
Twig::init();
?>