Created
October 31, 2019 09:53
-
-
Save alexeyshockov/60967a12c32769151772f203257d741f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Twig\Environment; | |
use Twig\Loader\ArrayLoader; | |
function twig_template(string $template): callable | |
{ | |
$twigEnvironment = new Environment($loader = new ArrayLoader()); | |
$loader->setTemplate($templateName = md5($template), $template); | |
return static function (array $params = []) use ($twigEnvironment, $templateName) { | |
return $twigEnvironment->render($templateName, $params); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment