$files->filterBy($key [, $operator], $value [, $split])
Filters the collection by any field and value and with a set of filtering operators
-
$key (string)
A field name or a method of the file, e.g. extension -
$operator (string)
See list of filter methods below; if not a valid filter method the second parameter will be the value -
$value (mixed)
-
$split (string)
Character to split by while filtering -
return ($files)
Example
// 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');
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 (added in Kirby 2.3.2) |
!= | all values that don't match |
not in | takes an array as parameter, matches all values that are not included in the array (added in Kirby 2.3.2) |
*= | 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 |