Improved the error message when a template is not found

This commit is contained in:
Javier Eguiluz 2016-01-19 09:57:11 +01:00
parent e9d951a882
commit 968476b707

View File

@ -89,10 +89,14 @@ class FilesystemLoader extends \Twig_Loader_Filesystem
}
if (false === $file || null === $file) {
list($namespace, $name) = $this->parseName($logicalName);
$paths = $this->getPaths($namespace);
array_walk($paths, function (&$path) use ($name) { $path .= '/'.$name; });
throw new \Twig_Error_Loader(sprintf('Unable to find template "%s" (tried: %s).', $name, implode(', ', $paths)), -1, null, $previous);
try {
list($namespace, $name) = $this->parseName($logicalName);
$paths = sprintf(' (looked into: %s)', implode(', ', $this->getPaths($namespace)));;
} catch (\Twig_Error_Loader $e) {
$paths = '';
}
throw new \Twig_Error_Loader(sprintf('Unable to find template "%s"%s.', $name, $paths, -1, null, $previous));
}
return $this->cache[$logicalName] = $file;