Reference

$files->filterBy()

Filters elements by one of the predefined filter methods.

$files->filterBy(string $field, $args = null): Kirby\Cms\Files

Parameters

Name Type Default Description
$field string
$args mixed null

Return type

Kirby\Cms\Files

Values for $args

$args can be a string, true, false or a combination of a filter method and an argument. In case of the in or not in filters, the third argument must be an array.

Examples

// filter by extension
$images = $page->images()->filterBy('extension', 'jpg');

// filter by custom field value
$images = $page->images()->filterBy('gallery', 'gallery-2');

// filter by filenames containing a string
$files = $page->files()->filterBy('filename', '*=', '-document');

// filter all types except documents
$files = $page->files()->filterBy('type', '!=', 'document');

// filter all files that have a template assigned
$files = $page->files()->filterBy('template', true);

Available filter methods

Method Function
== all values that match exactly
in takes an array as parameter, matches all values that are included in the array
!= all values that don't match
not in takes an array as parameter, matches all values that are not included in the array
*= all values that contain the given string
> all values that are greater than the given value
>= all values that are greater or equal the given value
< all values that are smaller than the given value
<= all values that are smaller or equal the given value

Source code

kirby/src/Toolkit/Collection.php#L251