Skip to content

Kirby 6.0.0

$files->not()

Returns a Collection without the given element(s)

$files->not(object|array|string ...$keys): Files

Parameters

Name Type Default Description
...$keys objectorarrayorstring no default value Any number of keys, objects or collections, as individual arguments or in arrays

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\Cms\Collection

Examples

<ul>
  <?php foreach($page->files()->not($page->files()->first()) as $file): ?>
  <li>
    <a href="<?= $file->url() ?>">
      <?= html($file->filename()) ?>
    </a>
  </li>
  <?php endforeach ?>
</ul>

Array of ids, collections or objects as argument

You can also use an array of ids, collections or objects or a mixture of them to exclude from a collection:

An array of ids

$files = $page->images()->not(['image-a.jpg', 'image-b.jpg']);

An array of objects

$files = $page->images()->not([image('image-a.jpg'), image('image-b.jpg')]);

An array of mixed values

$files = $page->files()->not([$page->files()->template('cover'), image('image-a.jpg'), 'image-b.jpg']);