{"record":{"id":"fbdb22769cf36e3b","repo":"symfony/symfony","slug":"the-app-current-route-variable-is-not-available","errorCode":null,"errorMessage":"The \"app.current_route\" variable is not available.","messagePattern":"The \"app\\.current_route\" variable is not available\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Symfony/Bridge/Twig/AppVariable.php","lineNumber":199,"sourceCode":"            return $session->getFlashBag()->all();\n        }\n\n        if (\\is_string($types)) {\n            return $session->getFlashBag()->get($types);\n        }\n\n        $result = [];\n        foreach ($types as $type) {\n            $result[$type] = $session->getFlashBag()->get($type);\n        }\n\n        return $result;\n    }\n\n    public function getCurrent_route(): ?string\n    {\n        if (!isset($this->requestStack)) {\n            throw new \\RuntimeException('The \"app.current_route\" variable is not available.');\n        }\n\n        return $this->getRequest()?->attributes->get('_route');\n    }\n\n    /**\n     * @return array<string, mixed>\n     */\n    public function getCurrent_route_parameters(): array\n    {\n        if (!isset($this->requestStack)) {\n            throw new \\RuntimeException('The \"app.current_route_parameters\" variable is not available.');\n        }\n\n        return $this->getRequest()?->attributes->get('_route_params') ?? [];\n    }\n}\n","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/symfony/symfony/blob/698e28026c22cf35d032cdb6e800db48b1535790/src/Symfony/Bridge/Twig/AppVariable.php#L181-L217","documentation":"AppVariable::getCurrent_route() exposes `app.current_route` and requires a RequestStack injected via setRequestStack(). Without it, the property is uninitialized and the getter throws a RuntimeException before it can read the `_route` attribute from the current request.","triggerScenarios":"A template references `{{ app.current_route }}` (or code calls getCurrent_route()) when no RequestStack was wired into AppVariable — same root cause as app.request, since current_route is read from request attributes.","commonSituations":"Rendering templates that build navigation/breadcrumbs using the current route in CLI, workers, or tests without a request context; standalone Twig missing RequestStack wiring.","solutions":["Inject the request stack via `$appVariable->setRequestStack($requestStack)`.","Ensure a request with the `_route` attribute is pushed onto the stack in non-HTTP contexts.","Pass the current route to templates explicitly when rendering outside a request lifecycle.","Confirm the `twig.app_variable` service wires the request_stack."],"exampleFix":"// before\n$app = new \\Symfony\\Bridge\\Twig\\AppVariable();\n$app->getCurrent_route(); // throws\n\n// after\n$app->setRequestStack($requestStack);\n$app->getCurrent_route(); // returns _route or null","handlingStrategy":"validation","validationCode":"// Push a request with _route before rendering in non-HTTP contexts\n$request = \\Symfony\\Component\\HttpFoundation\\Request::create('/');\n$request->attributes->set('_route', 'current_route_name');\n$requestStack->push($request);","typeGuard":null,"tryCatchPattern":"try {\n    $route = $appVariable->getCurrent_route();\n} catch (\\RuntimeException $e) {\n    $route = null;\n}","preventionTips":["Wire setRequestStack() on AppVariable before reading app.current_route.","Push a request carrying _route onto the stack when rendering navigation templates in CLI/workers.","Pass the current route explicitly to templates outside a request lifecycle.","Confirm the `twig.app_variable` service wires the request_stack."],"tags":["twig","http","routing","templating","dependency-injection"],"analyzedSha":"698e28026c22cf35d032cdb6e800db48b1535790","analyzedAt":"2026-08-06T23:40:49.025Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}