Reference

Guide

$files->filterBy()

Filters elements by one of the predefined filter methods.

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

Parameters

Name Type Default Description
$field string
$args array 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
!= all values that don't match
in takes an array as parameter, matches all values that are included in the array
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 do not contain the given string
^= all values that start with the given string
!^= all values that do not start with the given string
$= all values that end with the given sttring
!$= all values that do not end with a given string
* all values that match the given pattern
!* all values that do not match the given pattern
between all values that match the given range
maxlength all values that match the given maxLength
minlength all values that match the given minLength
maxwords all values that match the given max number of words
minwords all values that match the given min number of words
> 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

More information

Filtering compendium

Inherited from

Kirby\Toolkit\Collection

Source code

kirby/src/Toolkit/Collection.php#L256