From 4a647d35b1586f4185effbd82f35657140f8ee38 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sun, 8 Jan 2017 15:50:05 +0100 Subject: [PATCH] compatibility of FilesystemLoader with Twig 2.0 This fixes #161. --- Twig/Loader/FilesystemLoader.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Twig/Loader/FilesystemLoader.php b/Twig/Loader/FilesystemLoader.php index 5fe44e4..d04bacd 100644 --- a/Twig/Loader/FilesystemLoader.php +++ b/Twig/Loader/FilesystemLoader.php @@ -51,12 +51,13 @@ public function setActiveTheme(ActiveTheme $activeTheme = null) * Otherwise the template is located using the locator from the twig library. * * @param string|TemplateReferenceInterface $template The template + * @param bool $throw When true, a \Twig_Error_Loader exception will be thrown if a template could not be found * * @return string The path to the template file * * @throws \Twig_Error_Loader if the template could not be found */ - protected function findTemplate($template) + protected function findTemplate($template, $throw = true) { $logicalName = (string) $template; @@ -85,7 +86,11 @@ protected function findTemplate($template) } if (false === $file || null === $file) { - throw new \Twig_Error_Loader(sprintf('Unable to find template "%s".', $logicalName), -1, null, $previous); + if ($throw) { + throw new \Twig_Error_Loader(sprintf('Unable to find template "%s".', $logicalName), -1, null, $previous); + } + + return false; } return $this->cache[$logicalName] = $file;