What exactly is the site object of a page?

In my use case I need a collection of children of all generations of a page plus the page itself. I found that $page->site() seems to give me what I need, but I’m hesitant if it is the correct approach. I first thought of using $page->index() and merging it with the page itself, but this would be easier.
So, does $page->site() indeed give me a collection, or is it just a happy accident that it works in my case?

This is how I intend to use it:

<?php foreach($results as $result): ?>
  <?php if($artist->site()->has($result)): ?>
    …
  <?php endif ?>
<?php endforeach ?>

$artist is a certain page and $results are search results.

Edit: Okay, I think I already found that $page->site() does not give me what I want after all. Question still stands: What is the site object? And what would be the best approach to get the wanted collection? Is there a method for it, or do I need to merge something?

Docs: $site says:

The $site object represents the root of your site with all the information stored in /content/site.txt . It’s also the access point for registered users, available languages on multi-language sites and more.

Learn more about $site

Follow the last link to know more about $site.


If you have read my last link, you know, that $artist->site() [that is $site] has no function $site->has(), so this part of your code is wrong.

There is no method to fetch a particular page index including the page itself, so you have to merge the page with $page->index().

if($artist) {
$index = $artist->index();
$artistIndex =   $index->prepend($artist->uri(), $artist);
}

You can wrap this in a custom page method, if you like:

page::$methods['fullindex'] = function($page) {
  $index = $page->index();
  $fullIndex =   $index->prepend($page->uri(), $page);
  return $fullIndex;
};

See https://getkirby.com/docs/developer-guide/objects/page

Then call in your template:

if($artist && artist->fullIndex()->has($result)) {
  // do stuff
}