twigphp/Twig · error · Twig\Error\LoaderError
Unable to find one of the following templates
Error message
Unable to find one of the following templates: "%s".
What it means
Environment::resolveTemplate throws this Twig\LoaderError when none of the names passed (an array of template candidates) could be loaded by the configured loader. It is the multi-candidate variant of 'template not found': every entry in the array was tried and each failed.
Solutions
- Check that at least one of the listed names exists under a registered loader path; fix the name or create the template.
- Verify loader configuration: addPath() directories and register()ed namespaces actually cover the candidate names.
- Dump loader paths ($loader->getPaths() / getNamespaces()) and compare with the names passed.
- On case-sensitive filesystems, confirm the file name's case matches exactly.
- If using ArrayLoader or a custom loader, confirm its cache/source map contains the keys.
Example fix
// before
$loader = new FilesystemLoader('/wrong/dir');
$twig->resolveTemplate(['base.html.twig', 'fallback.html.twig']);
// after
$loader = new FilesystemLoader(__DIR__.'/templates');
$twig->resolveTemplate(['base.html.twig', 'fallback.html.twig']); Defensive patterns
Strategy: validation
Validate before calling
$loader = new \Twig\Loader\FilesystemLoader(__DIR__.'/templates');
foreach ($names as $n) {
if (!$loader->exists($n)) {
error_log("Template candidate missing: $n (paths: ".implode(',', $loader->getPaths()).')');
}
}
if ($loader->exists($names[0])) { $twig->resolveTemplate($names); } Try / catch
try {
$tpl = $twig->resolveTemplate(['theme/x.html.twig', 'default/x.html.twig']);
} catch (\Twig\Error\LoaderError $e) {
$tpl = $twig->resolveTemplate('fallback.html.twig');
} Prevention
- Use $loader->exists($name) to probe templates before resolving arrays of candidates.
- Register namespaces explicitly with addPath($dir, $ns) and use @ns/name syntax.
- Keep template names in constants/config rather than scattered string literals.
- Remember Linux filesystems are case-sensitive; enforce lowercase template filenames.
When it happens
Trigger: Calling $twig->resolveTemplate(['a.html.twig', 'b.html.twig']) or rendering with an array of template names where no name exists according to the loader (FilesystemLoader paths misconfigured, wrong namespace, wrong extension).
Common situations: Twig\FilesystemLoader addPath pointing at the wrong directory; using @namespace/name while the namespace was never registered; rendering an array of theme fallbacks where all candidates were removed/renamed; case-sensitivity mismatches on Linux.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Template " " is not defined .
- Template " " does not exist.
- Template " " is not defined.
- Template " " is not defined.
- There are no registered paths for namespace
AI-assisted analysis of twigphp/Twig@a414c3a491 (2026-09-13).
Data as JSON: /api/errors/7625632a40714970.
Report an issue: GitHub.
Appendix: source
Thrown at src/Environment.php:516
$count = \count($names);
foreach ($names as $name) {
if ($name instanceof Template) {
trigger_deprecation('twig/twig', '3.9', 'Passing a "%s" instance to "%s" is deprecated.', Template::class, __METHOD__);
return new TemplateWrapper($this, $name);
}
if ($name instanceof TemplateWrapper) {
return $name;
}
if (1 !== $count && !$this->getLoader()->exists($name)) {
continue;
}
return $this->load($name);
}
throw new LoaderError(\sprintf('Unable to find one of the following templates: "%s".', implode('", "', $names)));
}
/**
* @return void
*/
public function setLexer(Lexer $lexer)
{
$this->lexer = $lexer;
}
/**
* @throws SyntaxError When the code is syntactically wrong
*/
public function tokenize(Source $source): TokenStream
{
if (null === $this->lexer) {
$this->lexer = new Lexer($this);
}View on GitHub (pinned to a414c3a491)