# template_structure

URL: /kida/api/parser/blocks/template_structure/
Section: blocks
Description: Template structure block parsing for Kida parser.

Provides mixin for parsing template structure statements (block, extends, include, from_import).

Uses inline TYPE_CHECKING declarations for host attributes.
See: plan/rfc-mixin-protocol-typing.md

---

> For a complete page index, fetch /kida/llms.txt.

Open LLM text
(/kida/api/parser/blocks/template_structure/index.txt)

Share with AI

Ask Claude
(https://claude.ai/new?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fkida%2Fapi%2Fparser%2Fblocks%2Ftemplate_structure%2Findex.txt)

Ask ChatGPT
(https://chatgpt.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fkida%2Fapi%2Fparser%2Fblocks%2Ftemplate_structure%2Findex.txt)

Ask Gemini
(https://gemini.google.com/app?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fkida%2Fapi%2Fparser%2Fblocks%2Ftemplate_structure%2Findex.txt)

Ask Copilot
(https://copilot.microsoft.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fkida%2Fapi%2Fparser%2Fblocks%2Ftemplate_structure%2Findex.txt)

Module

#
`parser.blocks.template_structure`

Template structure block parsing for Kida parser.

Provides mixin for parsing template structure statements (block, extends, include, from_import).

Uses inline TYPE_CHECKING declarations for host attributes.
See: plan/rfc-mixin-protocol-typing.md

1Class

## Classes

`TemplateStructureBlockParsingMixin`

9

▼

Mixin for parsing template structure blocks.

Host attributes and cross-mixin dependencies are decl…

Mixin for parsing template structure blocks.

Host attributes and cross-mixin dependencies are declared via inline
TYPE_CHECKING blocks. Inherits block stack management from BlockStackMixin.

#### Methods

Internal Methods
9

▼

`_parse_template_context`

0

`TemplateContext`

▼

Parse {% template name: Type, name: Type, ... %}.

Type declarations for templa…

`def _parse_template_context(self) -> TemplateContext`

Parse {% template name: Type, name: Type, ... %}.

Type declarations for template context variables. Used by the
type checker (`kida check --typed`) to validate that templates
receive the expected variables.

Example::

```
{% template page: Page, site: Site %}
{% template items: list, count: int %}
```

##### Returns

`TemplateContext`

`_parse_block_tag`

0

`Block`

▼

Parse {% block name [if expr] %}...{% end %} or {% endblock %}.

The optional `…

`def _parse_block_tag(self) -> Block`

Parse {% block name [if expr] %}...{% end %} or {% endblock %}.

The optional`if expr`guard causes the block to be skipped
during full render when the expression is falsy.

##### Returns

`Block`

`_parse_globals_tag`

0

`Globals`

▼

Parse {% globals %}...{% end %} — setup block for render_block().

The globals …

`def _parse_globals_tag(self) -> Globals`

Parse {% globals %}...{% end %} — setup block for render_block().

The globals block defines macros and variables that are available during
both full render() and render_block(). This solves the problem of macros
defined in base templates being invisible during fragment rendering.

Only one {% globals %} block is allowed per template.

##### Returns

`Globals`

`_parse_imports_tag`

0

`Imports`

▼

Parse {% imports %}...{% end %} — intent-revealing imports for fragments.

Same…

`def _parse_imports_tag(self) -> Imports`

Parse {% imports %}...{% end %} — intent-revealing imports for fragments.

Same semantics as {% globals %} but signals: these are imports for
fragment/block scope. Compiles to _globals_setup.

##### Returns

`Imports`

`_parse_fragment_tag`

0

`Block`

▼

Parse {% fragment name %}...{% end %} — fragment-only block.

Fragment blocks a…

`def _parse_fragment_tag(self) -> Block`

Parse {% fragment name %}...{% end %} — fragment-only block.

Fragment blocks are skipped during full template render() and only
rendered when explicitly requested via render_block(). This avoids
UndefinedError for blocks whose variables are only provided during
fragment rendering (e.g., htmx OOB swaps, SSE partials).

##### Returns

`Block`

`_parse_extends`

0

`Extends`

▼

Parse {% extends "base.html" %}.

`def _parse_extends(self) -> Extends`

##### Returns

`Extends`

`_parse_include`

0

`Include`

▼

Parse {% include "partial.html" [with context] [ignore missing] %}.

`def _parse_include(self) -> Include`

##### Returns

`Include`

`_parse_import`

0

`Import`

▼

Parse {% import "template.html" as f [with context] %}.

`def _parse_import(self) -> Import`

##### Returns

`Import`

`_parse_from_import`

0

`FromImport`

▼

Parse {% from "template.html" import name1, name2 as alias %}.

`def _parse_from_import(self) -> FromImport`

##### Returns

`FromImport`
