liquid.filters.wild
module
liquid.filters.wild
Provides some wild filters
Functions
function
liquid.filters.wild.
ifelse
(
env
, value
, test
, test_args=()
, true=None
, true_args=()
, false=None
, false_args=()
)
An if-else filter, implementing a tenary-like filter.
Use ifelse
or if_else
.
Examples
>>> {{ a | ifelse: isinstance, (int, ),>>> "plus", (1, ),
>>> "append", (".html", ) }}
>>> # 2 when a = 1
>>> # "a.html" when a = "a"
Parameters
value
(any) — The base valuetest
(any) — The test callable or filter nametest_args
(any, optional) — Other args (value as the first arg) for the testtrue
(any, optional) — The callable or filter name when test is Truetrue_args
(any, optional) — Other args (value as the first arg) for the trueWhen this is None, return the true callable itself or the name of the filter it selffalse
(any, optional) — The callable or filter name when test is Falsefalse_args
(any, optional) — Other args (value as the first arg) for the falseWhen this is None, return the false callable itself or the name of the filter it self
Returns (any)
The result of true of test result is True otherwise result of false.
function
liquid.filters.wild.
call
(
fn
, *args
, **kwargs
)
Call a function with passed arguments
Examples
>>> {{ int | call: "1" | plus: 1 }}>>> # 2
Parameters
fn
— The callable*args
— and**kwargs
— The arguments for the callable
Returns (any)
The result of calling the function
function
liquid.filters.wild.
each
(
array
, fn
, *args
, **kwargs
)
Call a function for each item in an array.
With wild mode, you can use the 'map' filter to apply a function to each item in an array. However, this filter is different from the 'map' filter in that it takes the array as the first argument and additional arguments passed to the function are allowed.
Examples
>>> {{ floor | map: [1.1, 2.1, 3.1] | list }}>>> # [1, 2, 3]
>>> {{ [1.1, 2.1, 3.1] | each: floor }}
>>> # [1, 2, 3]
>>> {{ [1.1, 2.1, 3.1] | each: plus, 1 }}
>>> # [2.2, 3.2, 4.2]
Parameters
array
(any) — The arrayfn
— The callable
Returns (any)
The result of calling the function for each item in the array