Reference

Guide

$files->filter()

Filters elements by a custom filter function or an array of filters

$files->filter(\Closure $filter): Kirby\Cms\Files

Parameters

Name Type Default Description
$filter Closure

Return type

Kirby\Cms\Files

Example

// fetch files with a caption
$files = $page->files()->filter(function($file) {
  return $file->caption() != '';
});

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

// fetch large files
$largeFiles = $page->files()->filter(function($file) {
  return $file->size() > (1024*1024*2);
});

Inherited from

Kirby\Toolkit\Collection

Source code

kirby/src/Toolkit/Collection.php#L222