Skip to content

Kirby 4.4.1

$files->filter()

Filters elements by one of the predefined filter methods, by a custom filter function or an array of filters

$files->filter(string|array|\Closure $field, mixed ...$args = null): Kirby\Cms\Files

Parameters

Name Type Default
$field * string|array|Closure
... $args mixed null

Return type

Kirby\Cms\Files

This method does not modify the existing $files object but returns a new object with the changes applied. Learn more →

Parent class

Kirby\Cms\Files inherited from Kirby\Toolkit\Collection

Example

// fetch files with a caption
$files = $page->files()->filter(
    fn ($file) => $file->caption() != ''
);

// fetch files grouped by a gallery field
$images = $page->images()->filter(
    fn ($image) => $image->gallery() == 'gallery-2'
);

// fetch large files
$largeFiles = $page->files()->filter(
    fn ($file) => $file->size() > (1024*1024*2)
);

More information

Filtering compendium