Skip to content

Instantly share code, notes, and snippets.

@alexeyshockov
Created October 31, 2019 09:53
Show Gist options
  • Save alexeyshockov/60967a12c32769151772f203257d741f to your computer and use it in GitHub Desktop.
Save alexeyshockov/60967a12c32769151772f203257d741f to your computer and use it in GitHub Desktop.
<?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