{"record":{"id":"7625632a40714970","repo":"twigphp/Twig","slug":"unable-to-find-one-of-the-following-templates-s","errorCode":null,"errorMessage":"Unable to find one of the following templates: \"%s\".","messagePattern":"Unable to find one of the following templates: \"(.+?)\"\\.","errorType":"exception","errorClass":"Twig\\Error\\LoaderError","httpStatus":null,"severity":"error","filePath":"src/Environment.php","lineNumber":516,"sourceCode":"        $count = \\count($names);\n        foreach ($names as $name) {\n            if ($name instanceof Template) {\n                trigger_deprecation('twig/twig', '3.9', 'Passing a \"%s\" instance to \"%s\" is deprecated.', Template::class, __METHOD__);\n\n                return new TemplateWrapper($this, $name);\n            }\n            if ($name instanceof TemplateWrapper) {\n                return $name;\n            }\n\n            if (1 !== $count && !$this->getLoader()->exists($name)) {\n                continue;\n            }\n\n            return $this->load($name);\n        }\n\n        throw new LoaderError(\\sprintf('Unable to find one of the following templates: \"%s\".', implode('\", \"', $names)));\n    }\n\n    /**\n     * @return void\n     */\n    public function setLexer(Lexer $lexer)\n    {\n        $this->lexer = $lexer;\n    }\n\n    /**\n     * @throws SyntaxError When the code is syntactically wrong\n     */\n    public function tokenize(Source $source): TokenStream\n    {\n        if (null === $this->lexer) {\n            $this->lexer = new Lexer($this);\n        }","sourceCodeStart":498,"sourceCodeEnd":534,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/src/Environment.php#L498-L534","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\n$loader = new FilesystemLoader('/wrong/dir');\n$twig->resolveTemplate(['base.html.twig', 'fallback.html.twig']);\n\n// after\n$loader = new FilesystemLoader(__DIR__.'/templates');\n$twig->resolveTemplate(['base.html.twig', 'fallback.html.twig']);","handlingStrategy":"validation","validationCode":"$loader = new \\Twig\\Loader\\FilesystemLoader(__DIR__.'/templates');\nforeach ($names as $n) {\n    if (!$loader->exists($n)) {\n        error_log(\"Template candidate missing: $n (paths: \".implode(',', $loader->getPaths()).')');\n    }\n}\nif ($loader->exists($names[0])) { $twig->resolveTemplate($names); }","typeGuard":null,"tryCatchPattern":"try {\n    $tpl = $twig->resolveTemplate(['theme/x.html.twig', 'default/x.html.twig']);\n} catch (\\Twig\\Error\\LoaderError $e) {\n    $tpl = $twig->resolveTemplate('fallback.html.twig');\n}","preventionTips":["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."],"tags":["twig","loader","template-not-found"],"backgroundTag":"resource-not-found","analyzedSha":"a414c3a491defb5a60f2fc88ef79ff37c90010cd","analyzedAt":"2026-09-13T15:10:46.849Z","contentChangedAt":"2026-09-13T15:10:46.849Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}