Skip to content

Convenience functions

liquid2.parse

parse(
    source: str,
    *,
    name: str = "",
    globals: Mapping[str, object] | None = None
) -> Template

Parse source as a Liquid template using the default environment.

PARAMETER DESCRIPTION
source

Liquid template source code.

TYPE: str

name

An optional name for the template used in error messages.

TYPE: str DEFAULT: ''

globals

Variables that will be available to the resulting template.

TYPE: Mapping[str, object] | None DEFAULT: None

Return

A new template bound to the default environment.

liquid2.render

render(source: str, *args: Any, **kwargs: Any) -> str

Parse and render source as a Liquid template using the default environment.

Additional arguments are passed to dict() and will be available as template variables.

PARAMETER DESCRIPTION
source

Liquid template source code.

TYPE: str

*args

dict-like arguments added to the template render context.

TYPE: Any DEFAULT: ()

**kwargs

dict-like arguments added to the template render context.

TYPE: Any DEFAULT: {}

Return

The result of rendering source as a Liquid template.

liquid2.render_async async

render_async(source: str, *args: Any, **kwargs: Any) -> str

Parse and render source as a Liquid template using the default environment.

Additional arguments are passed to dict() and will be available as template variables.

PARAMETER DESCRIPTION
source

Liquid template source code.

TYPE: str

*args

dict-like arguments added to the template render context.

TYPE: Any DEFAULT: ()

**kwargs

dict-like arguments added to the template render context.

TYPE: Any DEFAULT: {}

Return

The result of rendering source as a Liquid template.

liquid2.extract_liquid

extract_liquid(
    fileobj: TextIO,
    keywords: list[str],
    comment_tags: list[str] | None = None,
    options: dict[object, object] | None = None,
) -> Iterator[MessageTuple]

A babel compatible translation message extraction method for Liquid templates.

See https://babel.pocoo.org/en/latest/messages.html

Keywords are the names of Liquid filters or tags operating on translatable strings. For a filter to contribute to message extraction, it must also appear as a child of a FilteredExpression and be a TranslatableFilter. Similarly, tags must produce a node that is a TranslatableTag.

Where a Liquid comment contains a prefix in comment_tags, the comment will be attached to the translatable filter or tag immediately following the comment. Python Liquid's non-standard shorthand comments are not supported.

Options are arguments passed to the liquid.Template constructor with the contents of fileobj as the template's source. Use extract_from_template to extract messages from an existing template bound to an existing environment.