TemplateEngine
Base classes¶
| Name | Children | Inherits |
|---|---|---|
| Protocol typing Base class for protocol classes. |
|
⋔ Inheritance diagram¶
graph TD
2442760286["engine.TemplateEngine"]
1073422405["typing.Protocol"]
3481597255["typing.Generic"]
2751680898["builtins.object"]
1073422405 --> 2442760286
3481597255 --> 1073422405
2751680898 --> 3481597255
🛈 DocStrings¶
Bases: Protocol
The engine surface: render strings / templates, register filters / tests / globals.
Filters, tests and globals are plain dicts: add or replace entries at any time,
the next render sees them. Templates are found by loader (a Jinja2 /
jinjarope loader; other backends adapt it).
Errors: render_string raises TemplateSyntaxError / TemplateRenderError
(original exception as __cause__). Template lookups by name raise
TemplateNotFoundError (minijinja) or jinja2.TemplateNotFound (Jinja2, both
are LookupErrors); other errors of render_template are the backend's own
(Jinja2: jinja2.TemplateError subclasses, minijinja: minijinja.TemplateError)
or the exception raised by a filter / global.
Source code in src/jinjarope/engine.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 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 | |
filters
instance-attribute
¶
filters: dict[str, Callable[..., Any]]
Filters by name ({{ x | name }}).
loader
instance-attribute
¶
The template loader (None: only template strings can be rendered).
tests
instance-attribute
¶
tests: dict[str, Callable[..., bool]]
Tests by name ({% if x is name %}).
__contains__
¶
add_template
¶
add_template_path
¶
get_source
¶
load_jinja_file
¶
load_jinja_file(
path: str | PathLike[str],
scope_prefix: str = "",
load_filters: bool = True,
load_tests: bool = True,
load_functions: bool = True,
load_config: bool = True,
load_loader: bool = True,
) -> None
Add the filters / tests / functions (and config, loader) of a JinjaFile.
Source code in src/jinjarope/engine.py
render_condition
¶
render_condition(
string: str, variables: dict[str, Any] | None = None, **kwargs: Any
) -> bool
Render a template string and return whether the result is truthy.
render_file
¶
render_file(
file: str | PathLike[str], variables: dict[str, Any] | None = None, **kwargs: Any
) -> str
Render a file (local path or fsspec URL) as template string.
render_string
¶
render_string(string: str, variables: dict[str, Any] | None = None, **kwargs: Any) -> str
render_template
¶
render_template(
template_name: str,
variables: dict[str, Any] | None = None,
block_name: str | None = None,
parent_template: str | None = None,
**kwargs: Any
) -> str
Render a template of the loader (or only one block of it).