$page API variable / Page class

Class used by all Page objects in ProcessWire.

The $page API variable represents the current page being viewed. However, the documentation here also applies to all Page objects that you may work with in the API. We use $page as the most common example throughout the documentation, but you can substitute that with any variable name representing a Page.


Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the Page class also inherits all the methods and properties of: WireData and Wire.

Show $var?             Show args?        

Common

NameReturnSummary 
$page->child()
Page NullPageReturn the page’s first single child that matches the given selector.
Can also be used as property: $page->child
 
$page->children()
PageArray arrayReturn this page’s children, optionally filtered by a selector
Can also be used as property: $page->children
 
$page->created int Unix timestamp of when the page was created.  
$page->createdUser User The user that created this page. Returns a User or a NullUser. 
$page->edit()
string bool mixedGet front-end editable output for field (requires PageFrontEdit module to be installed)
$page->find()
PageArrayFind descendant pages matching given selector 
$page->findOne()
Page NullPageFind one descendant page matching given selector 
$page->get(string $key)
mixedGet the value of a Page property (see details for several options) 
$page->hasChildren()
intReturn the number of visible children, optionally with conditions
Can also be used as property: $page->hasChildren
 
$page->hasStatus($status)
boolDoes this page have the given status? 
$page->httpUrl()
stringReturns the URL to the page, including scheme and hostname
Can also be used as property: $page->httpUrl
 
$page->if($key)
mixed string boolIf value is available for $key return or call $yes condition (with optional $no condition)
$page->matches($selector)
boolGiven a selector, return whether or not this Page matches it 
$page->modified int Unix timestamp of when the page was last modified.  
$page->modifiedUser User The user that last modified this page. Returns a User or a NullUser. 
$page->name string The name assigned to the page, as it appears in the URL  
$page->numChildren()
intReturn number of all children, optionally with conditions
Can also be used as property: $page->numChildren
 
$page->numParents()
intReturn number of parents (depth relative to homepage) that this page has, optionally filtered by a selector
Can also be used as property: $page->numParents
 
$page->of()
boolGet or set the current output formatting state of the page 
$page->parent()
PageReturn this page’s parent Page, or–if given a selector–the closest matching parent.
Can also be used as property: $page->parent
 
$page->parents()
PageArrayReturn this page’s parent pages, or the parent pages matching the given selector.
Can also be used as property: $page->parents
 
$page->path()
stringReturns the Page’s path from the ProcessWire installation root.
Can also be used as property: $page->path
$page->published int Unix timestamp of when the page was published.  
$page->rootParent()
PageGet the lowest-level, non-homepage parent of this page
Can also be used as property: $page->rootParent
$page->save()
boolSave the entire page to the database, or just a field from it 
$page->set(string $key, mixed $value)
Page WireDataSet the value of a page property 
$page->template Template string The Template object this page is using. The template name (string) may also be used for assignment. 
$page->title string The page’s title (headline) text 
$page->url()
stringReturns the URL to the page (optionally with additional $options)
Can also be used as property: $page->url
 

Traversal

NameReturnSummary 
$page->child()
Page NullPageReturn the page’s first single child that matches the given selector.
Can also be used as property: $page->child
 
$page->children()
PageArray arrayReturn this page’s children, optionally filtered by a selector
Can also be used as property: $page->children
 
$page->closest($selector)
Page NullPageFind the closest parent page matching your selector 
$page->descendant()
Page NullPage) Find one descendant page, alias of `Page::findOne()`, see that method for details. @since 3.0.116
$page->descendants()
PageArray) Find descendant pages, alias of `Page::find()`, see that method for details. @since 3.0.116
$page->find()
PageArrayFind descendant pages matching given selector 
$page->findOne()
Page NullPageFind one descendant page matching given selector 
$page->hasChildren()
intReturn the number of visible children, optionally with conditions
Can also be used as property: $page->hasChildren
 
$page->hasLinks int Number of visible pages (to current user) linking to this page in Textarea/HTML fields.  
$page->hasReferences int Number of visible pages (to current user) referencing this page with page reference fields.  
$page->index()
intReturn the index/position of this page relative to siblings.
Can also be used as property: $page->index
 
$page->links()
PageArrayReturn pages linking to this one (in Textarea/HTML fields)
Can also be used as property: $page->links
$page->next()
Page NullPageReturn the next sibling page
Can also be used as property: $page->next
 
$page->nextAll()
PageArray intReturn all sibling pages after this one, optionally matching a selector 
$page->nextUntil()
PageArrayReturn all sibling pages after this one until matching the one specified 
$page->numChildren()
intReturn number of all children, optionally with conditions
Can also be used as property: $page->numChildren
 
$page->numDescendants()
intReturn number of descendants (children, grandchildren, great-grandchildren, …), optionally with conditions
Can also be used as property: $page->numDescendants
 
$page->numLinks int Total number of pages manually linking to this page in Textarea/HTML fields.  
$page->numReferences int Total number of pages referencing this page with Page reference fields.  
$page->numReferencing int Total number of other pages this page is pointing to (referencing) with Page fields.  
$page->parent()
PageReturn this page’s parent Page, or–if given a selector–the closest matching parent.
Can also be used as property: $page->parent
 
$page->parents()
PageArrayReturn this page’s parent pages, or the parent pages matching the given selector.
Can also be used as property: $page->parents
 
$page->parentsUntil()
PageArrayReturn all parents from current page till the one matched by $selector 
$page->prev()
Page NullPageReturn the previous sibling page
Can also be used as property: $page->prev
 
$page->prevAll()
Page NullPage intReturn all sibling pages before this one, optionally matching a selector 
$page->prevUntil()
PageArrayReturn all sibling pages before this one until matching the one specified 
$page->references()
PageArray arrayReturn pages that have Page reference fields pointing to this one (references)
Can also be used as property: $page->references
$page->referencing PageArray Return pages that this page is referencing by way of Page reference fields.  
$page->rootParent()
PageGet the lowest-level, non-homepage parent of this page
Can also be used as property: $page->rootParent
$page->siblings()
PageArrayReturn this Page’s sibling pages, optionally filtered by a selector.
Can also be used as property: $page->siblings
 

Manipulation

NameReturnSummary 
$page->addStatus($statusFlag)
$thisAdd the specified status to this page 
$page->addUrl($url)
boolAdd a new URL that redirects to this page and save immediately (returns false if already taken).
$page->delete()
boolDelete this page from the database 
$page->isChanged()
boolHas the Page changed since it was loaded? 
$page->of()
boolGet or set the current output formatting state of the page 
$page->removeStatus($statusFlag)
$thisRemove the specified status from this page 
$page->removeUrl($url)
boolRemove a URL that redirects to this page and save immediately.
$page->resetTrackChanges()
$thisClears out any tracked changes and turns change tracking ON or OFF 
$page->save()
boolSave the entire page to the database, or just a field from it 
$page->set(string $key, mixed $value)
Page WireDataSet the value of a page property 
$page->setAndSave($key)
boolQuickly set field value(s) and save to database 
$page->setName(string $value)
$thisSet the page name, optionally for specific language
$page->setQuietly(string $key, mixed $value)
$thisQuietly set the value of a page property. 
$page->status()
int array PageGet or set current status
Can also be used as property: $page->status
 
$page->trash()
boolMove this page to the trash 

Date time

NameReturnSummary 
$page->created int Unix timestamp of when the page was created.  
$page->createdStr string Date/time when the page was created (formatted date/time string).  
$page->modified int Unix timestamp of when the page was last modified.  
$page->modifiedStr string Date/time when the page was last modified (formatted date/time string).  
$page->published int Unix timestamp of when the page was published.  
$page->publishedStr string Date/time when the page was published (formatted date/time string).  

Access

NameReturnSummary 
$page->addable()
boolReturns true if the current user can add children to the page, false if not. Optionally specify the page to be added for additional access checking.
Can also be used as property: $page->addable
$page->deletable()
boolAlias of deleteable().
Can also be used as property: $page->deletable
$page->deleteable()
boolReturns true if the page is deleteable by the current user, false if not.
Can also be used as property: $page->deleteable
$page->editable()
boolReturns true if the page (and optionally field) is editable by the current user, false if not.
Can also be used as property: $page->editable
$page->getAccessParent()
Page NullPageReturns the page from which role/access settings are inherited from 
$page->getAccessRoles()
PageArrayReturn Roles (PageArray) that have access to this page 
$page->getAccessTemplate()
Template nullReturns the template from which role/access settings are inherited from 
$page->hasAccessRole($role)
boolReturns whether this page has the given access role 
$page->listable()
boolReturns true if the page is listable by the current user, false if not.
Can also be used as property: $page->listable
$page->moveable()
boolReturns true if the current user can move this page. Optionally specify the new parent to check if the page is moveable to that parent.
Can also be used as property: $page->moveable
$page->publishable()
boolReturns true if the page is publishable by the current user, false if not.
Can also be used as property: $page->publishable
$page->restorable()
boolReturns true if page is in the trash and is capable of being restored to its original location. @since 3.0.107
$page->sortable()
boolReturns true if the current user can change the sort order of the current page (within the same parent).
Can also be used as property: $page->sortable
$page->trashable()
boolReturns true if the page is trashable by the current user, false if not.
Can also be used as property: $page->trashable
$page->viewable()
boolReturns true if the page (and optionally field) is viewable by the current user, false if not.
Can also be used as property: $page->viewable

Output rendering

NameReturnSummary 
$page->of()
boolGet or set the current output formatting state of the page 
$page->render()
string mixedReturns rendered page markup. If given a $fieldName argument, it behaves same as the renderField() method.
Can also be used as property: $page->render
$page->renderField(string $fieldName)
mixed stringRender given $fieldName using site/templates/fields/ markup file
$page->renderValue(mixed $value)
mixed stringRender given $value using /site/templates/fields/ markup file

Status

NameReturnSummary 
$page->addStatus($statusFlag)
$thisAdd the specified status to this page 
$page->hasStatus($status)
boolDoes this page have the given status? 
$page->isHidden()
boolDoes this page have a 'hidden' status? 
$page->isLocked()
boolDoes this page have a 'locked' status? 
$page->isTrash()
boolIs this Page in the trash? 
$page->isUnpublished()
boolDoes this page have a 'unpublished' status? 
$page->removeStatus($statusFlag)
$thisRemove the specified status from this page 
$page->status()
int array PageGet or set current status
Can also be used as property: $page->status
 
$page->statusPrevious int null Previous status, if status was changed.  

Constants

NameReturnSummary 
Page::statusHidden const1024Page is hidden and excluded from page finding methods unless overridden by selector (name: "hidden"). 
Page::statusIncomplete const128 
Page::statusLocked const4Indicates page is locked for changes (name: "locked") 
Page::statusUnpublished const2048Page is unpublished (not publicly visible) and excluded from page finding methods unless overridden (name: "unpublished"). 

Languages

Multi-language methods require these core modules: LanguageSupport, LanguageSupportFields, LanguageSupportPageNames.

NameReturnSummary 
$page->getLanguageValue($language, $field)
PageGet value for field in language (requires LanguageSupport module). $language may be ID, language name or Language object. Field should be field name (string).
$page->getLanguages()
PageArray nullGet languages active for this page and viewable by current user 
$page->localHttpUrl()
stringReturn the page URL (including scheme and hostname) in the current user's language, or specify $language argument (Language object, name, or ID).
$page->localName()
stringReturn the page name in the current user’s language, or specify $language argument (Language object, name, or ID), or TRUE to use default page name when blank (instead of 2nd argument).
$page->localPath()
stringReturn the page path in the current user's language, or specify $language argument (Language object, name, or ID).
$page->localUrl()
stringReturn the page URL in the current user's language, or specify $language argument (Language object, name, or ID).
$page->setLanguageValue($language, $field, $value)
PageSet value for field in language (requires LanguageSupport module). $language may be ID, language name or Language object. Field should be field name (string).

System

Most system properties directly correspond to columns in the pages database table.

NameReturnSummary 
$page->created int Unix timestamp of when the page was created.  
$page->created_users_id int ID of created user.  
$page->id int The numbered ID of the current page  
$page->modified int Unix timestamp of when the page was last modified.  
$page->modified_users_id int ID of last modified user.  
$page->name string The name assigned to the page, as it appears in the URL  
$page->parent_id int The numbered ID of the parent page or 0 if homepage or not assigned.  
$page->published int Unix timestamp of when the page was published.  
$page->sort int Sort order of this page relative to siblings (applicable when manual sorting is used).  
$page->sortfield()
stringReturn the field name by which children are sorted
Can also be used as property: $page->sortfield
 
$page->templates_id int The numbered ID of the template usedby this page.  

Advanced

NameReturnSummary 
$page->count()
intReturns number of children page has, affected by output formatting mode. 
$page->fieldgroup Fieldgroup Fieldgroup used by page template. Shorter alias for $page->template->fieldgroup (same as $page->fields)  
$page->fields Fieldgroup All the Fields assigned to this page (via its template). Returns a Fieldgroup.  
$page->filesManager()
PagefilesManagerReturn instance of PagefilesManager specific to this Page
Can also be used as property: $page->filesManager
 
$page->getField($field)
Field nullGet a Field object in context or NULL if not valid for this page 
$page->getFields()
FieldsArrayReturns a FieldsArray of all Field objects in the context of this Page 
$page->getFormatted(string $key)
mixedGet the formatted value of a field, regardless of output formatting state 
$page->getInputfield(string $fieldName)
Inputfield InputfieldWrapper nullGet a single Inputfield for the given field name 
$page->getInputfields()
null InputfieldWrapperReturn all Inputfield objects necessary to edit this page 
$page->getIterator()
ArrayObjectEnables iteration of the page's properties and fields with PHP’s foreach() 
$page->getMarkup(string $key)
stringReturn the markup value for a given field name or {tag} string
$page->getText(string $key)
stringSame as getMarkup() except returned value is plain text 
$page->getUnformatted(string $key)
mixedGet the unformatted value of a field, regardless of output formatting state 
$page->hasField($field)
bool stringReturns whether or not given $field name, ID or object is valid for this Page 
$page->isPublic()
boolIs this page public and viewable by all?
$page->meta()
WireDataDB string array int floatGet or set page’s persistent meta data 
$page->outputFormatting bool Whether output formatting is enabled or not.  
$page->setQuietly(string $key, mixed $value)
$thisQuietly set the value of a page property. 

For hooks

These methods are only useful for hooking and should not be called directly.

NameReturnSummary 
$page->callUnknown(string $method, array $arguments)
null mixedIf method call resulted in no handler, this hookable method is called.
$page->edit()
string bool mixedGet front-end editable output for field (requires PageFrontEdit module to be installed)
$page->getUnknown(string $key)
null mixedHookable method called when a request to a field was made that didn't match anything
$page->loaded()
(nothing)For hooks to listen to, triggered when page is loaded and ready

Urls

NameReturnSummary 
$page->addUrl($url)
boolAdd a new URL that redirects to this page and save immediately (returns false if already taken).
$page->editUrl()
stringReturn the URL necessary to edit this page
Can also be used as property: $page->editUrl
 
$page->httpUrl()
stringReturns the URL to the page, including scheme and hostname
Can also be used as property: $page->httpUrl
 
$page->localHttpUrl()
stringReturn the page URL (including scheme and hostname) in the current user's language, or specify $language argument (Language object, name, or ID).
$page->localPath()
stringReturn the page path in the current user's language, or specify $language argument (Language object, name, or ID).
$page->localUrl()
stringReturn the page URL in the current user's language, or specify $language argument (Language object, name, or ID).
$page->path()
stringReturns the Page’s path from the ProcessWire installation root.
Can also be used as property: $page->path
$page->removeUrl($url)
boolRemove a URL that redirects to this page and save immediately.
$page->url()
stringReturns the URL to the page (optionally with additional $options)
Can also be used as property: $page->url
 
$page->urls()
arrayReturn all URLs that this page can be accessed from (excluding URL segments and pagination)
Can also be used as property: $page->urls
 

Previous

Provides access to the previously set runtime value of some Page properties.

NameReturnSummary 
$page->namePrevious string Previous name, if changed. Blank if not.  
$page->parentPrevious Page null Previous parent, if parent was changed.  
$page->statusPrevious int null Previous status, if status was changed.  
$page->templatePrevious Template null Previous template, if template was changed.  

Additional methods and properties

In addition to the methods and properties above, Page also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.137

Twitter updates

  • ProcessWire 3.0.142 has a lot of updates but the biggest is the addition of custom fields support for file and image fields. In this post, we take a closer look at that, and also outline all of the new features in the just-released FormBuilder v40— More
    11 October 2019
  • This week’s dev branch version brings you improvements to ProcessWire’s input->cookie API variable, plus it adds the ability to modify system URLs and paths at runtime. This post also includes some examples to demonstrate just how useful this can be— More
    20 September 2019
  • New post: This week we’ll take a look at a new version of FormBuilder that's on the way (with a screencast), as well as the latest version of the core: ProcessWire 3.0.140— More
    6 September 2019

Latest news

  • ProcessWire Weekly #283
    The 283rd issue of ProcessWire Weekly introduces ProcessWire 3.0.142 and FormBuilder v40, highlights some conference content, and features a new weekly poll continuing with the #processwireworks theme. Read on!
    Weekly.pw / 12 October 2019
  • ProcessWire 3.0.142 core updates
    This latest version of the core on the dev branch has a lot of updates, bnd the biggest is the addition of custom fields support for file and image fields. In this post, we take a closer look and also outline all of the new features in the just-released FormBuilder v40.
    Blog / 11 October 2019
  • Subscribe to weekly ProcessWire news

“Indeed, if ProcessWire can be considered as a CMS in its own right, it also offers all the advantages of a CMF (Content Management Framework). Unlike other solutions, the programmer is not forced to follow the proposed model and can integrate his/her ways of doing things.” —Guy Verville, Spiria Digital Inc.