Environment::resolveTemplate now accepts instances of TemplateWrapper

This commit is contained in:
Victor Welling
2017-11-10 15:08:17 +01:00
committed by Fabien Potencier
parent acfa0311e7
commit 78a4f2fb59
+8 -4
View File
@@ -562,12 +562,12 @@ class Twig_Environment
/** /**
* Tries to load a template consecutively from an array. * Tries to load a template consecutively from an array.
* *
* Similar to loadTemplate() but it also accepts Twig_TemplateInterface instances and an array * Similar to loadTemplate() but it also accepts instances of Twig_Template and
* of templates where each is tried to be loaded. * Twig_TemplateWrapper, and an array of templates where each is tried to be loaded.
* *
* @param string|Twig_Template|array $names A template or an array of templates to try consecutively * @param string|Twig_Template|Twig_TemplateWrapper|array $names A template or an array of templates to try consecutively
* *
* @return Twig_Template * @return Twig_Template|Twig_TemplateWrapper
* *
* @throws Twig_Error_Loader When none of the templates can be found * @throws Twig_Error_Loader When none of the templates can be found
* @throws Twig_Error_Syntax When an error occurred during compilation * @throws Twig_Error_Syntax When an error occurred during compilation
@@ -583,6 +583,10 @@ class Twig_Environment
return $name; return $name;
} }
if ($name instanceof Twig_TemplateWrapper) {
return $name;
}
try { try {
return $this->loadTemplate($name); return $this->loadTemplate($name);
} catch (Twig_Error_Loader $e) { } catch (Twig_Error_Loader $e) {