From: Fabien Potencier Date: Sun, 4 Aug 2013 13:09:59 +0000 (+0200) Subject: fixed template_from_string() cache side-effects X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=a834dbb22457ffad95977670fe78fe2973919eb3;p=web%2Fkonrad%2Ftwig.git fixed template_from_string() cache side-effects --- diff --git a/lib/Twig/Extension/StringLoader.php b/lib/Twig/Extension/StringLoader.php index a1cef87..5e1a60d 100644 --- a/lib/Twig/Extension/StringLoader.php +++ b/lib/Twig/Extension/StringLoader.php @@ -43,14 +43,16 @@ class Twig_Extension_StringLoader extends Twig_Extension */ 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('__string_template__' => $template)), + new Twig_Loader_Array(array($name => $template)), $current = $env->getLoader(), )); $env->setLoader($loader); try { - $template = $env->loadTemplate('__string_template__'); + $template = $env->loadTemplate($name); } catch (Exception $e) { $env->setLoader($current);