Skip to content

environment

Tools and classes for managing the Jinja2 rendering environment.

Classes

InheritanceLoader

InheritanceLoader(inheritance_map: InheritanceMap)

Bases: BaseLoader

Load templates from inherited templates of the same name.

Methods:

get_source
get_source(
    environment: Environment, template: str
) -> tuple[str, str | None, Callable[[], bool] | None]

Load the template.

InheritanceRef dataclass

InheritanceRef(name: str, index: int = 0)

A parsed reference to one rung of a template’s inheritance chain.

InheritanceLoader addresses a specific ancestor of a template with an "{index}/{name}" string (e.g. "2/a.txt"); this is the value object for that string.

Methods:

format
format() -> str

Render this reference back into the loader’s "{index}/{name}" string form.

parse classmethod
parse(template: str) -> InheritanceRef

Parse a loader template name, e.g. "2/a.txt" or the un-prefixed "a.txt".

SuperUndefined

Bases: Undefined

Let calls to super() work ok.

Methods:

__call__
__call__() -> str

If the undefined is called (like super()) it outputs an empty string.

__getattr__
__getattr__(name: str) -> Any

Override the superclass’ getattr method to handle the jinja_pass_arg attribute.

Functions:

load_environment

load_environment(
    template_map: Optional[InheritanceMap] = None,
    extensions: Optional[list] = None,
) -> Environment

Load the Jinja2 template environment.

PARAMETER DESCRIPTION
template_map

The template inheritance used to load the templates

TYPE: Optional[InheritanceMap] DEFAULT: None

extensions

A list of Jinja extensions to load into the environment

TYPE: Optional[list] DEFAULT: None

RETURNS DESCRIPTION
Environment

The Jinja environment