Reference

Guide

$page

The $page object is the heart and soul of Kirby. It is used to construct pages and all their dependencies like children, files, content, etc.

You can extend this set of methods with custom page methods or in a page model.

How to fetch the $page object

The $page class is available in Kirby's templates/snippets etc. through the $page variable that - unless otherwise defined – always refers to the current page. However, you can also define a $page object by calling a specific page using the page() helper:

$page = page('somepage');

Or getting it from a collection of pages

$page = $pages->first();

Content fields

The $page class offers a magic caller for your content fields. Instead of getting them via e.g.

$page->content()->get('your_field')

you can use the shorthand

$page->your_field()

Examples

With the $page object defined, you can start using the methods of the class:

Get a field of the page

<?= $page->title() ?>

Get the children of the page

<?php $children = $page->children() ?>

Get all images of the page

<?php $images = $page->images() ?>

Check if the page is active

<?php e($page->isActive(), 'active') ?>

Check if the page has draft children

if ($page->hasDrafts()) {
  echo "This page still has some children that haven't been published yet";
}