Reference

Guide

$pages->not()

Returns a Collection without the given element(s)

$pages->not(\mixxed[] $keys = null): Kirby\Cms\Collection

Parameters

Name Type Default Description
$keys mixxed[] null

any number of keys, passed as individual arguments

Return type

Kirby\Cms\Collection

Example

<h2>All pages except project-b</h2>
<ul>
  <?php foreach($page->children()->not('project-b') as $subpage): ?>
  <li>
    <a href="<?= $subpage->url() ?>">
      <?= $subpage->title()->html() ?>
    </a>
  </li>
  <?php endforeach ?>
</ul>

Pass collection as argument

(since 2.3.0+)
You can now pass a collection as argument as well:

<ul>
  <?php
  $excluded = $page->children()->filterBy('template', 'some_template');
  foreach($page->children()->not($excluded) as $subpage): ?>
  <li>
    <a href="<?= $subpage->url() ?>">
      <?= $subpage->title()->html() ?>
    </a>
  </li>
  <?php endforeach ?>
</ul>

Inherited from

Kirby\Cms\Collection

Source code

kirby/src/Cms/Collection.php#L203