betty.jinja2 package

Submodules

Module contents

Provide rendering utilities using Jinja2.

class betty.jinja2.EntityContexts(*entities)[source]

Bases: object

Parameters:
*entities

class betty.jinja2.Environment(app)[source]

Bases: Environment

Parameters:
app

property context_class : type[Context]

The template context holds the variables of a template. It stores the values passed to the template and also the names the template exports. Creating instances is neither supported nor useful as it’s created automatically at various stages of the template evaluation and should not be created by hand.

The context is immutable. Modifications on parent must not happen and modifications on vars are allowed from generated template code only. Template filters and global functions marked as pass_context() get the active context passed as first argument and are allowed to access the context read-only.

The template context supports read only dict operations (get, keys, values, items, iterkeys, itervalues, iteritems, __getitem__, __contains__). Additionally there is a resolve() method that doesn’t fail with a KeyError but returns an Undefined object for missing variables.

filters : --is-rst--dict[str, Callable[..., Any]]
globals : --is-rst--dict[str, Any]
tests : --is-rst--dict[str, Callable[..., bool]]
class betty.jinja2.Jinja2Provider[source]

Bases: object

property filters : dict[str, Callable[[...], Any]]
property globals : dict[str, Any]
new_context_vars()[source]
Return type:

dict[str, typing.Any]

property tests : dict[str, Callable[[...], bool]]
class betty.jinja2.Jinja2Renderer(environment, configuration)[source]

Bases: Renderer

Parameters:
environment

configuration

property file_extensions : set[str]
async render_file(file_path, *, job_context=None, localizer=None)[source]
Parameters:
file_path

job_context=None

localizer=None

Return type:

pathlib.Path

betty.jinja2.context_app(context)[source]

Get the current app from the Jinja2 context.

Parameters:
context

Return type:

betty.app.App

betty.jinja2.context_job_context(context)[source]

Get the current job context from the Jinja2 context.

Parameters:
context

Return type:

betty.job.Context | None

betty.jinja2.context_localizer(context)[source]

Get the current localizer from the Jinja2 context.

Parameters:
context

Return type:

betty.locale.Localizer