generate_render_partial()

Create a render_partial function bound to a specific renderer.

Usage

Source

generate_render_partial(renderer: Callable[..., Any], markup: Literal[True] = ...) -> Callable[..., Markup]
 
generate_render_partial(renderer: Callable[..., Any], markup: Literal[False]) -> Callable[..., str]
 
generate_render_partial(renderer: Callable[..., Any], markup: bool) -> Callable[..., Union[Markup, str]]

Parameters

renderer: Callable[..., Any]

Callable that renders a template name plus keyword arguments to a string.

markup: bool = True
When True (the default), results are wrapped in markupsafe.Markup.

Returns

Callable[..., Union[Markup, str]]
A callable with the same signature as render_partial that uses the bound renderer.

Note

The template name reaches renderer exactly as the template wrote it. The built-in renderers hand it to Jinja’s loader, which refuses names that leave the templates folder (.. segments, absolute paths); a custom renderer that loads files some other way must enforce that itself.

Example

Install a custom renderer as the render_partial global:

def renderer(template_name: str, **data) -> str:
    return env.get_template(template_name).render(**data)

env.globals.update(render_partial=jinja_partials.generate_render_partial(renderer))