Module

nodes.structure

Template structure nodes for Kida AST.

Classes

TemplateContext 1 ▼
Type declaration: {% template page: Page, site: Site %}

Type declaration: {% template page: Page, site: Site %}

Attributes

Name Type Description
declarations Sequence[tuple[str, str]] —
Extends 1 ▼
Template inheritance: {% extends "base.html" %}

Template inheritance: {% extends "base.html" %}

Attributes

Name Type Description
template Expr —
BlockModifier 2 ▼
Literal framework metadata attached to a block or fragment.

Literal framework metadata attached to a block or fragment.

Attributes

Name Type Description
name str —
value str | int | float | bool | None —
Block 7 ▼
Named block for inheritance: {% block name %}...{% end %}

Named block for inheritance: {% block name %}...{% end %}

Attributes

Name Type Description
name str —
body Sequence[Node] —
scoped bool —
required bool —
fragment bool —
condition Expr | None —
modifiers tuple[BlockModifier, ...] —
Globals 1 ▼
Setup block for macros/variables available during render_block().

Setup block for macros/variables available during render_block().

Attributes

Name Type Description
body Sequence[Node] —
Imports 1 ▼
Imports block — {% imports %}...{% end %}. Same semantics as {% globals %} but signals intent: the…

Imports block — {% imports %}...{% end %}.

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

Attributes

Name Type Description
body Sequence[Node] —
Include 3 ▼
Include another template: {% include "partial.html" %}

Include another template: {% include "partial.html" %}

Attributes

Name Type Description
template Expr —
with_context bool —
ignore_missing bool —
Import 3 ▼
Import functions from template: {% import "funcs.html" as f %}

Import functions from template: {% import "funcs.html" as f %}

Attributes

Name Type Description
template Expr —
target str —
with_context bool —
FromImport 3 ▼
Import specific functions: {% from "funcs.html" import button, card %}

Import specific functions: {% from "funcs.html" import button, card %}

Attributes

Name Type Description
template Expr —
names Sequence[tuple[str, str | None]] —
with_context bool —
Template 3 ▼
Root node representing a complete template.

Root node representing a complete template.

Attributes

Name Type Description
body Sequence[Node] —
extends Extends | None —
context_type TemplateContext | None —
Cache 4 ▼
Fragment caching: {% cache key %}...{% end %}

Fragment caching: {% cache key %}...{% end %}

Attributes

Name Type Description
key Expr —
body Sequence[Node] —
ttl Expr | None —
depends Sequence[Expr] —
With 2 ▼
Jinja2-style context manager: {% with x = expr %}...{% end %}

Jinja2-style context manager: {% with x = expr %}...{% end %}

Attributes

Name Type Description
targets Sequence[tuple[str, Expr]] —
body Sequence[Node] —
WithConditional 4 ▼
Conditional with block: {% with expr as name %}...{% end %}

Conditional with block: {% with expr as name %}...{% end %}

Attributes

Name Type Description
expr Expr —
target Expr —
body Sequence[Node] —
empty Sequence[Node] —
Embed 3 ▼
Embed template with block overrides: {% embed 'card.html' %}...{% end %}

Embed template with block overrides: {% embed 'card.html' %}...{% end %}

Attributes

Name Type Description
template Expr —
blocks dict[str, Block] —
with_context bool —
Push 2 ▼
Push content to a named stack: {% push "scripts" %}...{% end %} Content is collected during render…

Push content to a named stack: {% push "scripts" %}...{% end %}

Content is collected during rendering and emitted where the corresponding{% stack "scripts" %}appears.

Attributes

Name Type Description
stack_name str —
body Sequence[Node] —
Stack 1 ▼
Emit collected stack content: {% stack "scripts" %} Outputs all content pushed to the named stack …

Emit collected stack content: {% stack "scripts" %}

Outputs all content pushed to the named stack via{% push %}.

Attributes

Name Type Description
stack_name str —
Provide 3 ▼
Provide a value to descendant consumers. ``{% provide key = expr %}...{% endprovide %}`` pushes *v…

Provide a value to descendant consumers.

{% provide key = expr %}...{% endprovide %}pushes value onto a per-key stack inRenderContext. Any descendant macro can read it viaconsume("key"). Stack-based for nesting: inner provides shadow outer ones for the same key.

Attributes

Name Type Description
name str —
value Expr —
body Sequence[Node] —
TransVar 2 ▼
Variable binding in {% trans name=expr %}. Binds a template expression to a simple name for use in…

Variable binding in {% trans name=expr %}.

Binds a template expression to a simple name for use inside the trans body as {{ name }}.

Attributes

Name Type Description
name str —
expr Expr —
Trans 4 ▼
{% trans %}...{% endtrans %} block. Represents a translatable string region. The singular field ho…

{% trans %}...{% endtrans %} block.

Represents a translatable string region. The singular field holds the message ID with %(name)s placeholders. When {% plural %} is present, the plural field holds the plural form and count_expr provides the ngettext dispatch value.

Attributes

Name Type Description
singular str —
plural str | None —
variables tuple[TransVar, ...] —
count_expr Expr | None —