htmy.jinja
JinjaContextFactory = Callable[[Context], Mapping[str, Any]]
module-attribute
A function that builds additional Jinja context entries from an htmy rendering context.
DefaultSlots
Bases: ContextAware
Context-aware holder of default named slots for JinjaTemplate.
The JinjaTemplate component looks up the DefaultSlots instance from the htmy rendering
context. If found, JinjaTemplate renders each slot and passes the rendered values as
markupsafe.Markup strings to the Jinja template.
Source code in htmy/jinja.py
slots
property
Mapping of slot names to htmy components.
__init__(slots=None)
Initialization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slots
|
Mapping[str, Component] | None
|
Optional mapping of slot names to |
None
|
JinjaTemplate
Component that renders a Jinja2 template.
The template source (a JinjaTemplates instance) must be in the htmy rendering context.
The looked up template source is used to load and render the template.
If a DefaultSlots instance is found in the htmy rendering context, its slots are rendered
and included in the slots context variable passed to Jinja. slots passed directly to this
component take precedence over DefaultSlots slots when both contain a slot with the same name.
Jinja context creation precedence: jinja_context, _build_context(), make_context, and
finally the reserved slots key.
Source code in htmy/jinja.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
__init__(template_name, *, jinja_context=None, make_context=None, slots=None)
Initialization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template_name
|
str
|
The name of the template to render. |
required |
jinja_context
|
Mapping[str, Any] | None
|
Optional mapping passed to Jinja as the template context. |
None
|
make_context
|
JinjaContextFactory | None
|
Optional callable that receives the |
None
|
slots
|
Mapping[str, Component] | None
|
Optional named slots to be rendered in the template. Values are |
None
|
Source code in htmy/jinja.py
htmy(context)
async
Renders the component.
Source code in htmy/jinja.py
JinjaTemplateSource
Bases: Protocol
Protocol for Jinja2 template sources such as jinja2.Environment.
Source code in htmy/jinja.py
JinjaTemplates
Bases: ContextAware
Context-aware Jinja2 template source that can be placed in the htmy rendering context.
The JinjaTemplate component looks up the JinjaTemplates instance from the htmy rendering
context to find and render templates.
Source code in htmy/jinja.py
source
property
The wrapped Jinja2 template source.
__init__(source)
Initialization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
JinjaTemplateSource
|
A Jinja2 template source, e.g. a |
required |