{"record":{"id":"7cf8922128e7ca03","repo":"twigphp/Twig","slug":"block-s-on-template-s-does-not-exist-7cf892","errorCode":null,"errorMessage":"Block \"%s\" on template \"%s\" does not exist.","messagePattern":"Block \"(.+?)\" on template \"(.+?)\" does not exist\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/Template.php","lineNumber":485,"sourceCode":"\n        // avoid RCEs when sandbox is enabled\n        if (null !== $template && !$template instanceof self) {\n            throw new \\LogicException('A block must be a method on a \\Twig\\Template instance.');\n        }\n\n        if (null !== $template) {\n            try {\n                $template->ensureSecurityChecked();\n                yield from $template->$block($context, $blocks);\n            } catch (\\Throwable $e) {\n                $template->handleException($e);\n            }\n        } elseif ($parent = $this->getParent($context)) {\n            yield from $parent->unwrap()->yieldBlock($name, $context, array_merge($this->blocks, $blocks), false, $templateContext ?? $this);\n        } elseif (isset($blocks[$name])) {\n            throw new RuntimeError(\\sprintf('Block \"%s\" should not call parent() in \"%s\" as the block does not exist in the parent template \"%s\".', $name, $blocks[$name][0]->getTemplateName(), $this->getTemplateName()), -1, $blocks[$name][0]->getSourceContext());\n        } else {\n            throw new RuntimeError(\\sprintf('Block \"%s\" on template \"%s\" does not exist.', $name, $this->getTemplateName()), -1, ($templateContext ?? $this)->getSourceContext());\n        }\n    }\n\n    /**\n     * Yields a parent block.\n     *\n     * This method is for internal use only and should never be called\n     * directly.\n     *\n     * @param string $name    The block name to display from the parent\n     * @param array  $context The context\n     * @param array  $blocks  The current set of blocks\n     *\n     * @return iterable<scalar|\\Stringable|null>\n     */\n    public function yieldParentBlock($name, array $context, array $blocks = []): iterable\n    {\n        if (isset($this->traits[$name])) {","sourceCodeStart":467,"sourceCodeEnd":503,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/src/Template.php#L467-L503","documentation":"Thrown by Template::yieldBlock as the final fallback: the requested block name exists neither in the template's own blocks, nor in any merged block set from callers, nor in a parent template. Twig raises a RuntimeError naming the missing block and template. This is the generic 'block not found' failure at render time.","triggerScenarios":"Calling block('name') in a template/expression, block('name', template) via TemplateWrapper or Template::renderBlock, or yieldBlock() directly, where no template in the inheritance/trait chain defines 'name'.","commonSituations":"Typo in the block name inside a block() expression or function call; rendering a template directly that was meant to be included/extended; refactoring that renamed a block but not all references; calling block() before the defining template is loaded via {% extends %}/{% use %}.","solutions":["Fix the block name typo in the block() call or {% block %} tag.","Define the missing block in the template or in a parent template.","If the block lives in another template, use {% extends %}, {% use %}, or the two-argument block('name', 'other.twig') form.","Verify the template actually being rendered is the one you expect (check {% extends %} and include paths)."],"exampleFix":"{{ block('contnt') }}\n\n{# after #}\n{{ block('content') }}","handlingStrategy":"try-catch","validationCode":"$blocks = $twig->load('base.twig')->getSourceContext(); // or grep template source for '{% block name %}' before calling block('name')","typeGuard":null,"tryCatchPattern":"try {\n    return $twig->render('page.twig', $ctx);\n} catch (\\Twig\\Error\\RuntimeError $e) {\n    if (str_contains($e->getMessage(), 'does not exist')) {\n        return $fallbackTemplate;\n    }\n    throw $e;\n}","preventionTips":["Grep templates for block() references and confirm each name is defined somewhere in the chain.","Avoid typos by reusing the same block-name constants in code and templates.","Keep block definitions in the direct parent or a {% use %} trait so resolution is local."],"tags":["twig","template","block","runtime-error"],"backgroundTag":"entity-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"}