Module

pages.renderer

Layout chain rendering with HX-Target-aware depth.

The renderer composes nested layouts inside-out using kida's render_with_blocks(). The HX-Targetheader determines how deep to render — only the layouts below the targeted element are rendered, preserving the outer shell on the client.

Functions

render_with_layouts 6 str
Render page content wrapped in its layout chain. Uses ``HX-Target`` to determi…
def render_with_layouts(env: Environment, *, layout_chain: LayoutChain, page_html: str, context: dict[str, Any], htmx_target: str | None = None, is_history_restore: bool = False) -> str

Render page content wrapped in its layout chain.

UsesHX-Targetto determine rendering depth:

  • No target (full page load or history restore): render all layouts nested, innermost first.
  • Target matches a layout: skip layouts at or above the matched one; render from the next layout down.
  • Target matches no layout: return page HTML as-is (fragment).
Parameters
Name Type Description
env Environment

The kidaEnvironmentfor loading layout templates.

layout_chain LayoutChain

Sequence of layouts from root (outermost) to deepest (closest to the page).

page_html str

Pre-rendered page content HTML.

context dict[str, Any]

Merged context variables for layout templates.

htmx_target str | None

Value ofHX-Target header, or None.

Default:None
is_history_restore bool

Whether this is an htmx history restore.

Default:False
Returns
str