{"record":{"id":"25989cc84703df79","repo":"emberjs/ember.js","slug":"unexpected-named-block-nested-in-a-normal-block","errorCode":null,"errorMessage":"Unexpected named block nested in a normal block","messagePattern":"Unexpected named block nested in a normal block","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/@glimmer/syntax/lib/v2/normalize.ts","lineNumber":913,"sourceCode":"      (c): c is ASTv2.ContentNode => !(c instanceof ASTv2.NamedBlock)\n    );\n  }\n}\n\nclass TemplateChildren extends Children {\n  assertTemplate(table: ProgramSymbolTable): ASTv2.Template {\n    if (isPresentArray(this.namedBlocks)) {\n      throw generateSyntaxError(`Unexpected named block at the top-level of a template`, this.loc);\n    }\n\n    return this.block.builder.template(table, this.nonBlockChildren, this.block.loc(this.loc));\n  }\n}\n\nclass BlockChildren extends Children {\n  assertBlock(table: BlockSymbolTable): ASTv2.Block {\n    if (isPresentArray(this.namedBlocks)) {\n      throw generateSyntaxError(`Unexpected named block nested in a normal block`, this.loc);\n    }\n\n    return this.block.builder.block(table, this.nonBlockChildren, this.loc);\n  }\n}\n\nclass ElementChildren extends Children {\n  constructor(\n    private el: BuildElement,\n    loc: SourceSpan,\n    children: (ASTv2.ContentNode | ASTv2.NamedBlock)[],\n    block: BlockContext\n  ) {\n    super(loc, children, block);\n  }\n\n  assertNamedBlock(name: SourceSlice, table: BlockSymbolTable): ASTv2.NamedBlock {\n    if (this.el.base.selfClosing) {","sourceCodeStart":895,"sourceCodeEnd":931,"githubUrl":"https://github.com/emberjs/ember.js/blob/26f97246a8bf2e28edf26ac3093da2e86c04ffc5/packages/@glimmer/syntax/lib/v2/normalize.ts#L895-L931","documentation":"Named blocks cannot be nested inside an ordinary block — i.e. inside `{{#if}}`, `{{#each}}`, or any other normal `{{#...}}` block. BlockChildren.assertBlock throws when named blocks appear among a normal block's children.","triggerScenarios":"Compiling a template where `<:name>...</:name>` appears inside e.g. `{{#if cond}} ... <:name> ... {{/if}}`.","commonSituations":"Conditionally wrapping named blocks with `{{#if}}`; accidentally placing a named block after another block's content but still inside its curlies; copy-paste refactors.","solutions":["Move the named block to be a direct child of the element/component tag it belongs to.","To make a named block conditional, put the condition inside the named block, not around it.","Split into multiple invocations if different named block sets are needed per condition."],"exampleFix":"// before\n<Card>\n  {{#if this.showHeader}}\n    <:header>Hi</:header>\n  {{/if}}\n</Card>\n\n// after\n<Card>\n  <:header>{{#if this.showHeader}}Hi{{/if}}</:header>\n</Card>","handlingStrategy":"validation","validationCode":"// Named blocks must be direct children of a tag, not inside {{#blocks}}.\nfunction assertNamedBlocksNotNested(children) {\n  for (const c of children) {\n    if (c.type === 'block' && c.children.some(x => x.type === 'named-block')) {\n      throw new Error('Named block nested inside a normal {{#block}}');\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep `<:name>` blocks at the top level of their element/component tag.","Move conditionals inside named blocks instead of wrapping named blocks in `{{#if}}`.","Use `{{yield to=...}}` with `has-block` checks for conditional sections."],"tags":["glimmer","template-compiler","named-blocks","syntax-error"],"backgroundTag":"invalid-named-block-usage","analyzedSha":"26f97246a8bf2e28edf26ac3093da2e86c04ffc5","analyzedAt":"2026-09-01T05:01:28.182Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}