twigphp/Twig · error · LoaderError

There are no registered paths for namespace

Error message

There are no registered paths for namespace "%s".

What it means

When a namespaced template (@ns/name) is requested but no paths are registered for that namespace, findTemplate() records this error in errorCache and throws it. Namespaces are populated only by addPath()/prependPath() with an explicit namespace argument.

Solutions

  1. Register at least one path for the namespace: $loader->addPath($path, 'MyNamespace').
  2. Verify namespace spelling/case matches what's used in the @Namespace/ prefix.
  3. List existing namespaces via getNamespaces() to confirm what is registered.

Example fix

// before
$twig->render('@Blog/post.html.twig'); // namespace not registered
// after
$loader->addPath('/project/blog/templates', 'Blog');
$twig->render('@Blog/post.html.twig');
Defensive patterns

Strategy: validation

Validate before calling

$ns = str_starts_with($name, '@') ? substr($name, 1, (int)strpos($name, '/') - 1) : '__main__'; if (!in_array($ns, $loader->getNamespaces(), true)) { throw new \RuntimeException("Namespace '$ns' not registered"); }

Type guard

function namespaceRegistered(Twig\Loader\FilesystemLoader $loader, string $name): bool { if ($name[0] ?? '' !== '@') return true; $ns = substr($name, 1, (int)strpos($name, '/') - 1); return in_array($ns, $loader->getNamespaces(), true); }

Try / catch

try { $twig->render($name); } catch (Twig\Error\LoaderError $e) { if (str_contains($e->getMessage(), 'no registered paths')) { // register the namespace path and retry } }

Prevention

When it happens

Trigger: Rendering or loading '@MyNamespace/template.html.twig' when addPath($path, 'MyNamespace') was never called (or called with a different namespace spelling).

Common situations: Symfony bundles expecting a namespace registered in twig.paths config; case-sensitive namespace mismatches; forgetting to register an empty namespace for a theme.

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


AI-assisted analysis of twigphp/Twig@a414c3a491 (2026-09-13). Data as JSON: /api/errors/418f061aec189b16. Report an issue: GitHub.

Appendix: source

Thrown at src/Loader/FilesystemLoader.php:211

            [$namespace, $shortname] = $this->parseName($name);

            $this->validateName($shortname);
        } catch (LoaderError $e) {
            if (!$throw) {
                return null;
            }

            throw $e;
        }

        if (!isset($this->paths[$namespace])) {
            $this->errorCache[$name] = \sprintf('There are no registered paths for namespace "%s".', $namespace);

            if (!$throw) {
                return null;
            }

            throw new LoaderError($this->errorCache[$name]);
        }

        foreach ($this->paths[$namespace] as $path) {
            if (!$this->isAbsolutePath($path)) {
                $path = $this->rootPath.$path;
            }

            if (is_file($path.'/'.$shortname)) {
                if (false !== $realpath = realpath($path.'/'.$shortname)) {
                    return $this->cache[$name] = $realpath;
                }

                return $this->cache[$name] = $path.'/'.$shortname;
            }
        }

        $this->errorCache[$name] = \sprintf('Unable to find template "%s" (looked into: %s).', $name, implode(', ', $this->paths[$namespace]));

View on GitHub (pinned to a414c3a491)