filter_by

Filter a list of items based on a property value and optional predicate.

This filter provides powerful filtering capabilities for lists of maps, proplists, or resources by checking property values against predicates.

Basic Usage

Filter items where a property is defined (not undefined):

{{ items | filter_by:"price" }}

Returns only items that have a price property defined.

Using Predicates

Filter with a boolean predicate filter:

{{ items | filter_by:"active":"is_defined" }}

This applies the is_defined filter to each item's active property. It is possible to use all boolean filters.

Built-in Comparison Operators

  • eq - equal to

  • ne - not equal to

  • lt - less than

  • le - less than or equal to

  • gt - greater than

  • ge - greater than or equal to

  • between - between two values (inclusive)

  • in - value is in a list

  • not_in - value is not in a list

Examples:

{{ products | filter_by:"price":"gt":100 }}

Returns products with price greater than 100.

{{ items | filter_by:"status":"in":["active", "pending"] }}

Returns items where status is either "active" or "pending".

{{ orders | filter_by:"amount":"between":[50, 200] }}

Returns orders with amount between 50 and 200 (inclusive).

Filtering Resources

Works seamlessly with Zotonic resources:

{{ m.search[{query cat="product"}] | filter_by:"is_published":"eq":true }}

If the input is undefined, the filter returns undefined.

See also

filter, exclude, and extract