Skip to content

Filter helpers

liquid.filter.decimal_arg

decimal_arg(
    val: Any, default: Union[int, Decimal, None] = None
) -> Union[int, Decimal]

Return val as an int or decimal.

If val can't be cast to an int or decimal, return default.

liquid.filter.int_arg

int_arg(val: Any, default: Optional[int] = None) -> int

Return val as an int or default if val can't be cast to an int.

liquid.filter.math_filter

math_filter(_filter: FilterT) -> FilterT

Raise a FilterArgumentError if the filter value can not be a number.

liquid.filter.num_arg

num_arg(
    val: Any, default: Optional[NumberT] = None
) -> NumberT

Return val as an int or float.

If val can't be cast to an int or float, return default.

liquid.filter.sequence_filter

sequence_filter(_filter: FilterT) -> FilterT

A filter function decorator that coerces the left value to sequence.

This is intended to mimic the semantics of the reference implementation's InputIterator class.

liquid.filter.string_filter

string_filter(_filter: FilterT) -> FilterT

A filter function decorator that converts the first argument to a string.

liquid.filter.with_context

with_context(_filter: FilterT) -> FilterT

Pass the active render context to decorated filter functions.

If a function is decorated with with_context, that function should accept a context keyword argument, being the active render context.

PARAMETER DESCRIPTION
_filter

The filter function to decorate.

TYPE: FilterT

liquid.filter.with_environment

with_environment(_filter: FilterT) -> FilterT

Pass the active environment to decorated filter functions.

If a function is decorated with with_environment, that function should accept an environment keyword argument, being the active environment.

PARAMETER DESCRIPTION
_filter

The filter function to decorate.

TYPE: FilterT