{"record":{"id":"814bc07997890614","repo":"twigphp/Twig","slug":"template-s-is-not-defined-s","errorCode":null,"errorMessage":"Template \"%s\" is not defined%s.","messagePattern":"Template \"(.+?)\" is not defined(.+?)\\.","errorType":"exception","errorClass":"LoaderError","httpStatus":null,"severity":"error","filePath":"src/Loader/ChainLoader.php","lineNumber":77,"sourceCode":"    }\n\n    public function getSourceContext(string $name): Source\n    {\n        $exceptions = [];\n\n        foreach ($this->getLoaders() as $loader) {\n            if (!$loader->exists($name)) {\n                continue;\n            }\n\n            try {\n                return $loader->getSourceContext($name);\n            } catch (LoaderError $e) {\n                $exceptions[] = $e->getMessage();\n            }\n        }\n\n        throw new LoaderError(\\sprintf('Template \"%s\" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));\n    }\n\n    public function exists(string $name): bool\n    {\n        if (isset($this->hasSourceCache[$name])) {\n            return $this->hasSourceCache[$name];\n        }\n\n        foreach ($this->getLoaders() as $loader) {\n            if ($loader->exists($name)) {\n                return $this->hasSourceCache[$name] = true;\n            }\n        }\n\n        return $this->hasSourceCache[$name] = false;\n    }\n\n    public function getCacheKey(string $name): string","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/src/Loader/ChainLoader.php#L59-L95","documentation":"ChainLoader tries each registered loader in order when fetching a template's source. If every loader throws a LoaderError, it aggregates their messages and throws this LoaderError listing the name and the per-loader failure reasons (when any loader actually raised an error rather than just returning false from exists()).","triggerScenarios":"Calling getSourceContext($name) when no loader in the chain can find $name — e.g. template never created on disk, wrong namespace prefix, or loaders configured with wrong paths.","commonSituations":"Typos in template names; forgetting @namespace/ prefix when using namespaced paths; templates missing from all configured filesystem paths; load order pushing an intended loader after a failing one.","solutions":["Check the aggregated message for each loader's reason and fix the underlying loader misconfiguration.","Register the template or add the correct path with addPath() to an appropriate loader.","Verify the template name including its @Namespace/ prefix spelling."],"exampleFix":"// before\n$loader->addLoader(new FilesystemLoader('/wrong/path'));\n$chain->getSourceContext('index.html.twig');\n// after\n$fs = new FilesystemLoader('/correct/templates');\n$chain->addLoader($fs); // path that actually contains index.html.twig\n$chain->getSourceContext('index.html.twig');","handlingStrategy":"try-catch","validationCode":"foreach ($names as $name) { if (!$chain->exists($name)) { /* handle missing before getSourceContext */ } }","typeGuard":"function chainHas(Twig\\Loader\\ChainLoader $chain, string $name): bool { try { $chain->getSourceContext($name); return true; } catch (Twig\\Error\\LoaderError $e) { return false; } }","tryCatchPattern":"try { $src = $chain->getSourceContext($name); } catch (Twig\\Error\\LoaderError $e) { // message lists per-loader reasons; log $e->getMessage() and fall back }","preventionTips":["Call exists() before getSourceContext","Keep loader paths verified in bootstrap/config tests","Log the aggregated loader reasons to spot misconfiguration early"],"tags":["twig","loader","chain-loader","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"}