Skip to content

liquid.filters.wild

module

liquid.filters.wild

Provides some wild filters

Functions
  • call(fn, *args, **kwargs) (any) Call a function with passed arguments</>
  • each(array, fn, *args, **kwargs) (any) Call a function for each item in an array.</>
  • ifelse(env, value, test, test_args, true, true_args, false, false_args) (any) An if-else filter, implementing a tenary-like filter.</>
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 value
  • test (any) The test callable or filter name
  • test_args (any, optional) Other args (value as the first arg) for the test
  • true (any, optional) The callable or filter name when test is True
  • true_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 self
  • false (any, optional) The callable or filter name when test is False
  • false_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 array
  • fn The callable
Returns (any)

The result of calling the function for each item in the array