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

Classes

TemplateStructureBlockParsingMixin 8
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 8
_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 optionalif exprguard 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