function twig_template_from_string in Translation template extractor 6.3
Same name and namespace in other branches
- 7.3 vendor/Twig/Extension/StringLoader.php \twig_template_from_string()
Loads a template from a string.
<pre> {{ include(template_from_string("Hello {{ name }}")) }} </pre>
Parameters
Twig_Environment $env A Twig_Environment instance:
string $template A template as a string:
Return value
Twig_Template A Twig_Template instance
1 string reference to 'twig_template_from_string'
- Twig_Extension_StringLoader::getFunctions in vendor/
Twig/ Extension/ StringLoader.php - Returns a list of functions to add to the existing list.
File
- vendor/
Twig/ Extension/ StringLoader.php, line 44
Code
function twig_template_from_string(Twig_Environment $env, $template) {
$name = sprintf('__string_template__%s', hash('sha256', uniqid(mt_rand(), true), false));
$loader = new Twig_Loader_Chain(array(
new Twig_Loader_Array(array(
$name => $template,
)),
$current = $env
->getLoader(),
));
$env
->setLoader($loader);
try {
$template = $env
->loadTemplate($name);
} catch (Exception $e) {
$env
->setLoader($current);
throw $e;
}
$env
->setLoader($current);
return $template;
}