$site
The $site object is the root element for any site with pages. It represents the main content folder with its site.txt.
-
new Site()
-
$site->audio()
-
$site->blueprint()
-
$site->blueprints()
-
$site->breadcrumb()
-
$site->changeStorage()
-
$site->changeTitle()
-
$site->children()
-
$site->childrenAndDrafts()
-
$site->clone()
-
$site->code()
-
$site->content()
-
$site->createChild()
-
$site->createContent()
-
$site->createFile()
-
$site->createTranslations()
-
$site->decrement()
-
$site->documents()
-
$site->draft()
-
$site->drafts()
-
$site->errorPage()
-
$site->errorPageId()
-
$site->errors()
-
$site->exists()
-
$site->file()
-
$site->files()
-
$site->find()
-
$site->findPageOrDraft()
-
$site->getMethod()
-
$site->grandChildren()
-
$site->hardcopy()
-
$site->hasAudio()
-
$site->hasChildren()
-
$site->hasCode()
-
$site->hasDocuments()
-
$site->hasDrafts()
-
$site->hasFiles()
-
$site->hasImages()
-
$site->hasListedChildren()
-
$site->hasMethod()
-
$site->hasUnlistedChildren()
-
$site->hasVideos()
-
$site->homePage()
-
$site->homePageId()
-
$site->id()
-
$site->image()
-
$site->images()
-
$site->increment()
-
$site->index()
-
$site->inventory()
-
$site->is()
-
$site->isAccessible()
-
$site->isValid()
-
$site->kirby()
-
$site->lock()
-
$site->mediaDir()
-
$site->mediaRoot()
-
$site->mediaUrl()
-
$site->modified()
-
$site->page()
-
$site->pages()
-
$site->panel()
-
$site->permissions()
-
$site->previewUrl()
-
$site->purge()
-
$site->query()
-
$site->root()
-
$site->save()
-
$site->search()
-
$site->site()
-
$site->storage()
-
$site->toArray()
-
$site->toSafeString()
-
$site->toString()
-
$site->translation()
-
$site->translations()
-
$site->update()
-
$site->url()
-
$site->uuid()
-
$site->version()
-
$site->versions()
-
$site->videos()
-
$site->visit()
-
$site->wasModifiedAfter()
How to access the $site object
The $site variable is automatically available in your templates and snippets.
To access the $site object in extensions, you have to define it first:
// via the kirby object
$site = $kirby->site();
// using the `site()` helper
$site = site();
Content fields
The $site class offers a magic caller for your content fields. Instead of getting them via $site->content()->get('your_field'), you can use the shorthand $site->your_field().
Reserved names
You cannot use the shorthand for fields with names that conflict with methods of the $site class or with custom site methods. Besides the methods listed above, this also includes internal methods that are not part of the documented API. The following names are reserved:
apiUrl, audio, blueprint, blueprints, breadcrumb, changeStorage, changeTitle, children, childrenAndDrafts, clone, code, content, contentFileData, createChild, createContent, createDefaultContent, createFile, createTranslations, decrement, documents, draft, drafts, errorPage, errorPageId, errors, exists, file, files, find, findPageOrDraft, getMethod, grandChildren, hardcopy, hasAudio, hasChildren, hasCode, hasDocuments, hasDrafts, hasFiles, hasImages, hasListedChildren, hasMethod, hasUnlistedChildren, hasVideos, homePage, homePageId, id, image, images, increment, index, inventory, is, isAccessible, isLocked, isValid, kirby, lock, mediaDir, mediaRoot, mediaUrl, modified, page, pages, panel, permissions, previewUrl, purge, query, readContent, root, save, search, site, storage, toArray, toSafeString, toString, translation, translations, update, url, urlForLanguage, uuid, version, versions, videos, visit, wasModifiedAfter, writeContent
To access a field with a reserved name, use $site->content()->get('fieldname'). We recommend prefixing your field names instead to avoid any conflicts.
Examples
Get the site title
echo $site->title();
Get any custom field of the site
echo $site->description();
Get the files stored in the content folder
$siteFiles = $site->files();
Get all the pages of the site
$pageIndex = $site->index();
Get the URL of the site
$url = $site->url();