$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.
-
new Page()
-
$page->audio()
-
$page->blueprint()
-
$page->blueprints()
-
$page->changeNum()
-
$page->changeSlug()
-
$page->changeSort()
-
$page->changeStatus()
-
$page->changeTemplate()
-
$page->changeTitle()
-
$page->children()
-
$page->childrenAndDrafts()
-
$page->clone()
-
$page->code()
-
$page->content()
-
$page->contentFiles()
-
$page->copy()
-
Page::create()
-
$page->createChild()
-
$page->createFile()
-
$page->createNum()
-
$page->decrement()
-
$page->delete()
-
$page->depth()
-
$page->dirname()
-
$page->diruri()
-
$page->documents()
-
$page->draft()
-
$page->drafts()
-
$page->duplicate()
-
$page->errors()
-
$page->exists()
-
$page->file()
-
$page->files()
-
$page->find()
-
$page->findPageOrDraft()
-
$page->go()
-
$page->grandChildren()
-
$page->hardcopy()
-
$page->hasAudio()
-
$page->hasChildren()
-
$page->hasCode()
-
$page->hasDocuments()
-
$page->hasDrafts()
-
$page->hasFiles()
-
$page->hasImages()
-
$page->hasListedChildren()
-
$page->hasNext()
-
$page->hasNextListed()
-
$page->hasNextUnlisted()
-
$page->hasPrev()
-
$page->hasPrevListed()
-
$page->hasPrevUnlisted()
-
$page->hasTemplate()
-
$page->hasUnlistedChildren()
-
$page->hasVideos()
-
$page->id()
-
$page->image()
-
$page->images()
-
$page->increment()
-
$page->index()
-
$page->indexOf()
-
$page->intendedTemplate()
-
$page->is()
-
$page->isActive()
-
$page->isAncestorOf()
-
$page->isCacheable()
-
$page->isChildOf()
-
$page->isDescendantOf()
-
$page->isDescendantOfActive()
-
$page->isDraft()
-
$page->isErrorPage()
-
$page->isFirst()
-
$page->isHomeOrErrorPage()
-
$page->isHomePage()
-
$page->isLast()
-
$page->isListed()
-
$page->isLocked()
-
$page->isNth()
-
$page->isOpen()
-
$page->isPublished()
-
$page->isReadable()
-
$page->isSortable()
-
$page->isUnlisted()
-
$page->isValid()
-
$page->kirby()
-
$page->lock()
-
$page->modified()
-
$page->next()
-
$page->nextAll()
-
$page->nextListed()
-
$page->nextUnlisted()
-
$page->num()
-
$page->panelOptions()
-
$page->panelPickerData()
-
$page->parent()
-
$page->parents()
-
$page->permissions()
-
$page->prev()
-
$page->prevAll()
-
$page->prevListed()
-
$page->prevUnlisted()
-
$page->publish()
-
$page->purge()
-
$page->render()
-
$page->resortSiblingsAfterUnlisting()
-
$page->root()
-
$page->search()
-
$page->siblings()
-
$page->site()
-
$page->slug()
-
$page->status()
-
$page->template()
-
$page->templateSiblings()
-
$page->title()
-
$page->toArray()
-
$page->toString()
-
$page->translation()
-
$page->translations()
-
$page->uid()
-
$page->unpublish()
-
$page->update()
-
$page->uri()
-
$page->url()
-
$page->videos()
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();
When getting a specific page via the page()
helper or when trying to create a page object from field values stored in content, always verify that you have a page object before you call any of the Page methods.
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()
You can not use the shorthand for fields with names that conflict with the default methods of the $page
class (see above) or used by custom page methods.
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";
}