winter/modules/system/twig/Engine.php

41 lines
904 B
PHP
Raw Normal View History

2014-05-14 23:24:20 +10:00
<?php namespace System\Twig;
use System\Twig\Loader as TwigLoader;
use Twig\Environment as TwigEnvironment;
use Illuminate\Contracts\View\Engine as EngineInterface;
2014-05-14 23:24:20 +10:00
/**
* View engine used by the system, used for converting .htm files to twig.
*
* @package october\system
* @author Alexey Bobkov, Samuel Georges
*/
class Engine implements EngineInterface
{
/**
* @var TwigEnvironment
2014-05-14 23:24:20 +10:00
*/
protected $environment;
/**
* Constructor
*/
public function __construct(TwigEnvironment $environment)
2014-05-14 23:24:20 +10:00
{
$this->environment = $environment;
}
public function get($path, array $vars = [])
{
$previousAllow = TwigLoader::$allowInclude;
TwigLoader::$allowInclude = true;
2014-05-14 23:24:20 +10:00
$template = $this->environment->loadTemplate($path);
TwigLoader::$allowInclude = $previousAllow;
2014-05-14 23:24:20 +10:00
return $template->render($vars);
}
2014-10-18 11:58:50 +02:00
}