{"record":{"id":"1100ded1b96f35a4","repo":"twigphp/Twig","slug":"template-s-is-not-defined-filesystemloader","errorCode":null,"errorMessage":"Template \"%s\" is not defined.","messagePattern":"Template \"(.+?)\" is not defined\\.","errorType":"exception","errorClass":"LoaderError","httpStatus":null,"severity":"error","filePath":"src/Loader/FilesystemLoader.php","lineNumber":189,"sourceCode":"    }\n\n    /**\n     * @return string|null\n     */\n    protected function findTemplate(string $name, bool $throw = true)\n    {\n        $name = $this->normalizeName($name);\n\n        if (isset($this->cache[$name])) {\n            return $this->cache[$name];\n        }\n\n        if (isset($this->errorCache[$name])) {\n            if (!$throw) {\n                return null;\n            }\n\n            throw new LoaderError($this->errorCache[$name]);\n        }\n\n        try {\n            [$namespace, $shortname] = $this->parseName($name);\n\n            $this->validateName($shortname);\n        } catch (LoaderError $e) {\n            if (!$throw) {\n                return null;\n            }\n\n            throw $e;\n        }\n\n        if (!isset($this->paths[$namespace])) {\n            $this->errorCache[$name] = \\sprintf('There are no registered paths for namespace \"%s\".', $namespace);\n\n            if (!$throw) {","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/src/Loader/FilesystemLoader.php#L171-L207","documentation":"findTemplate() keeps an errorCache of previously failed lookups per template name. When a name is looked up again after a prior failure, this cached error message ('Template \"%s\" is not defined.') is rethrown instead of re-scanning, reporting that the template could not be found in any registered path for its namespace.","triggerScenarios":"Looking up a template name (via getSourceContext, getCacheKey, exists, isFresh) that failed before; the name has no matching file in any registered path, or the errorCache holds a stale failure from before a path was added without cache invalidation.","commonSituations":"Typo in template filename; template in wrong namespace; tests reusing a loader after paths changed (cache not invalidated); template deleted after a first failed lookup.","solutions":["Create the template file in one of the registered paths or fix its name.","Check registered paths with getPaths($namespace) and add the correct one via addPath().","Instantiate a fresh loader (or call setPaths) after config changes to clear the internal cache."],"exampleFix":"// before\n$twig->render('emial/welcome.html.twig'); // typo\n// after\n$twig->render('email/welcome.html.twig');","handlingStrategy":"validation","validationCode":"foreach ($templates as $t) { if (!$loader->exists($t) && !file_exists($candidatePath)) { warn(\"template $t unresolvable\"); } }","typeGuard":null,"tryCatchPattern":"try { $twig->render($name, $ctx); } catch (Twig\\Error\\LoaderError $e) { // check errorCache message; fix name or add path and recreate loader }","preventionTips":["Verify template filenames with linter/static checks","Recreate or reconfigure loaders after changing paths (errorCache persists)","Beware case-sensitivity across filesystems"],"tags":["twig","filesystem","template-not-found"],"backgroundTag":"file-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"}