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.
- Common
- Traversal
- Manipulation
- Date time
- Access
- Output rendering
- Status
- Constants
- Languages
- System
- Advanced
- For hooks
- Urls
- Files
- Previous
- Users
Common
Name | Return | Summary | |
---|---|---|---|
$page->child() $page->child() $page->child($selector = '', array $options = []) | Page NullPage | Return the page’s first single child that matches the given selector. Can also be used as property: $page->child | |
$page->children() $page->children() $page->children(string $selector = '', array $options = []) | PageArray array | Return this page’s children, optionally filtered by a selector Can also be used as property: $page->children | |
$page->find() $page->find() $page->find($selector = '', array $options = []) | PageArray | Find descendant pages matching given selector | |
$page->findOne() $page->findOne() $page->findOne($selector = '', array $options = []) | Page NullPage | Find one descendant page matching given selector | |
$page->get() $page->get(string $key) $page->get(string $key) | mixed | Get the value of a Page property (see details for several options) | |
$page->getMultiple() $page->getMultiple($keys) $page->getMultiple($keys, bool $assoc = false) | array | Get multiple Page property/field values in an array | |
$page->hasChildren() $page->hasChildren() $page->hasChildren($selector = true) | int | Return the number of visible children, optionally with conditions Can also be used as property: $page->hasChildren | |
$page->hasFile() $page->hasFile(string $file) $page->hasFile(string $file, array $options = []) | bool string | Does Page have given filename in its files directory? | |
$page->hasStatus() $page->hasStatus($status) $page->hasStatus($status) | bool | Does this page have the given status? | |
$page->httpUrl() $page->httpUrl() $page->httpUrl(array $options = []) | string | Returns the URL to the page, including scheme and hostname Can also be used as property: $page->httpUrl | |
$page->id | int | The numbered ID of the current page | |
$page->if() $page->if($key) $page->if($key, $yes = '', $no = '') | mixed string bool | If value is available for $key return or call $yes condition (with optional $no condition) | |
$page->name | string | The name assigned to the page, as it appears in the URL | |
$page->numChildren() $page->numChildren() $page->numChildren($selector = null) | int | Return number of all children, optionally with conditions Can also be used as property: $page->numChildren | |
$page->numParents() $page->numParents() $page->numParents(string $selector = '') | int | Return 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() $page->of() $page->of(bool $outputFormatting = null) | bool | Get or set the current output formatting state of the page | |
$page->parent() $page->parent() $page->parent($selector = '') | Page | Return this page’s parent Page, or–if given a selector–the closest matching parent. Can also be used as property: $page->parent | |
$page->parents() $page->parents() $page->parents($selector = '') | PageArray | Return this page’s parent pages, or the parent pages matching the given selector. Can also be used as property: $page->parents | |
$page->path() $page->path() $page->path() | string | Returns the Page’s path from the ProcessWire installation root. Can also be used as property: $page->path | |
$page->rootParent() $page->rootParent() $page->rootParent() | Page | Get the lowest-level, non-homepage parent of this page Can also be used as property: $page->rootParent | |
$page->save() $page->save() $page->save($field = null, array $options = []) | bool | Save the entire page to the database, or just a field from it | |
$page->set() $page->set(string $key, mixed $value) $page->set(string $key, mixed $value) | Page WireData | Set the value of a page property | |
$page->template() $page->template() $page->template($template = null) | Template null | Get or set template Can also be used as property: $page->template | |
$page->title | string | The page’s title (headline) text | |
$page->url() $page->url() $page->url($options = null) | string | Returns the URL to the page (optionally with additional $options) Can also be used as property: $page->url |
Traversal
Name | Return | Summary | |
---|---|---|---|
$page->child() $page->child() $page->child($selector = '', array $options = []) | Page NullPage | Return the page’s first single child that matches the given selector. Can also be used as property: $page->child | |
$page->children() $page->children() $page->children(string $selector = '', array $options = []) | PageArray array | Return this page’s children, optionally filtered by a selector Can also be used as property: $page->children | |
$page->closest() $page->closest($selector) $page->closest($selector) | Page NullPage | Find the closest parent page matching your selector | |
$page->descendant() $page->descendant() $page->descendant($selector = '', array $options = array) | Page NullPage | ) Find one descendant page, alias of `Page::findOne()`, see that method for details. @since 3.0.116 | |
$page->descendants() $page->descendants() $page->descendants($selector = '', array $options = array) | PageArray | ) Find descendant pages, alias of `Page::find()`, see that method for details. @since 3.0.116 | |
$page->find() $page->find() $page->find($selector = '', array $options = []) | PageArray | Find descendant pages matching given selector | |
$page->findOne() $page->findOne() $page->findOne($selector = '', array $options = []) | Page NullPage | Find one descendant page matching given selector | |
$page->hasChildren() $page->hasChildren() $page->hasChildren($selector = true) | int | Return 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() $page->index() $page->index($selector = '') | int | Return the index/position of this page relative to siblings. Can also be used as property: $page->index | |
$page->links() $page->links() $page->links($selector = '', $field = '') | PageArray | Return pages linking to this one (in Textarea/HTML fields) Can also be used as property: $page->links | |
$page->matches() $page->matches($s) $page->matches($s) | bool | Given a selector, return whether or not this Page matches using runtime/memory comparison | |
$page->matchesDatabase() $page->matchesDatabase($s) $page->matchesDatabase($s) | bool | Given a selector, return whether or not this Page matches by querying the database | |
$page->next() $page->next() $page->next($selector = '', PageArray $siblings = null) | Page NullPage | Return the next sibling page Can also be used as property: $page->next | |
$page->nextAll() $page->nextAll() $page->nextAll($selector = '', $getQty = false, bool $getPrev = false) | PageArray int | Return all sibling pages after this one, optionally matching a selector | |
$page->nextUntil() $page->nextUntil() $page->nextUntil($selector = '', $filter = '', PageArray $siblings = null) | PageArray | Return all sibling pages after this one until matching the one specified | |
$page->numChildren() $page->numChildren() $page->numChildren($selector = null) | int | Return number of all children, optionally with conditions Can also be used as property: $page->numChildren | |
$page->numDescendants() $page->numDescendants() $page->numDescendants($selector = null) | int | Return 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() $page->parent() $page->parent($selector = '') | Page | Return this page’s parent Page, or–if given a selector–the closest matching parent. Can also be used as property: $page->parent | |
$page->parents() $page->parents() $page->parents($selector = '') | PageArray | Return this page’s parent pages, or the parent pages matching the given selector. Can also be used as property: $page->parents | |
$page->parentsUntil() $page->parentsUntil() $page->parentsUntil($selector = '', $filter = '') | PageArray | Return all parents from current page till the one matched by $selector | |
$page->prev() $page->prev() $page->prev($selector = '', $siblings = null) | Page NullPage | Return the previous sibling page Can also be used as property: $page->prev | |
$page->prevAll() $page->prevAll() $page->prevAll($selector = '', $getQty = false) | Page NullPage int | Return all sibling pages before this one, optionally matching a selector | |
$page->prevUntil() $page->prevUntil() $page->prevUntil($selector = '', $filter = '', $siblings = null) | PageArray | Return all sibling pages before this one until matching the one specified | |
$page->references() $page->references() $page->references($selector = '', $field = '') | PageArray array | Return 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() $page->rootParent() $page->rootParent() | Page | Get the lowest-level, non-homepage parent of this page Can also be used as property: $page->rootParent | |
$page->siblings() $page->siblings() $page->siblings($selector = '', bool $includeCurrent = true) | PageArray | Return this Page’s sibling pages, optionally filtered by a selector. Can also be used as property: $page->siblings |
Manipulation
Date time
Name | Return | Summary | |
---|---|---|---|
$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
Name | Return | Summary | |
---|---|---|---|
$page->addable() $page->addable() $page->addable($pageToAdd = null) | bool | Returns 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() $page->deletable() $page->deletable() | bool | Alias of deleteable(). Can also be used as property: $page->deletable | |
$page->deleteable() $page->deleteable() $page->deleteable() | bool | Returns true if the page is deleteable by the current user, false if not. Can also be used as property: $page->deleteable | |
$page->editable() $page->editable() $page->editable($field = '', $checkPageEditable = true) | bool | Returns 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->getAccessParent() $page->getAccessParent(string $type = 'view') | Page NullPage | Returns the page from which role/access settings are inherited from | |
$page->getAccessRoles() $page->getAccessRoles() $page->getAccessRoles(string $type = 'view') | PageArray | Return Roles (PageArray) that have access to this page | |
$page->getAccessTemplate() $page->getAccessTemplate() $page->getAccessTemplate(string $type = 'view') | Template null | Returns the template from which role/access settings are inherited from | |
$page->hasAccessRole() $page->hasAccessRole($role) $page->hasAccessRole($role, string $type = 'view') | bool | Returns whether this page has the given access role | |
$page->listable() $page->listable() $page->listable() | bool | Returns true if the page is listable by the current user, false if not. Can also be used as property: $page->listable | |
$page->moveable() $page->moveable() $page->moveable($newParent = null) | bool | Returns 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() $page->publishable() $page->publishable() | bool | Returns true if the page is publishable by the current user, false if not. Can also be used as property: $page->publishable | |
$page->restorable() $page->restorable() $page->restorable() | bool | Returns true if page is in the trash and is capable of being restored to its original location. @since 3.0.107 | |
$page->sortable() $page->sortable() $page->sortable() | bool | Returns 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() $page->trashable() $page->trashable($orDeleteable = false) | bool | Returns true if the page is trashable by the current user, false if not. Can also be used as property: $page->trashable | |
$page->viewable() $page->viewable() $page->viewable($field = '', $checkTemplateFile = true) | bool | Returns 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
Name | Return | Summary | |
---|---|---|---|
$page->edit() $page->edit() $page->edit($key = null, $markup = null, $modal = null) | string bool mixed | Get front-end editable output for field (requires PageFrontEdit module to be installed) | |
$page->of() $page->of() $page->of(bool $outputFormatting = null) | bool | Get or set the current output formatting state of the page | |
$page->render() $page->render() $page->render($arg1 = null, $arg2 = null) | string mixed | Returns rendered page markup. Please see the `PageRender::renderPage()` method for arguments and usage details. Can also be used as property: $page->render | |
$page->renderField() $page->renderField(string $fieldName) $page->renderField(string $fieldName, string $file = '', $value = null) | mixed string | Render given $fieldName using site/templates/fields/ markup file | |
$page->renderValue() $page->renderValue(mixed $value) $page->renderValue(mixed $value, string $file = '') | mixed string | Render given $value using /site/templates/fields/ markup file |
Status
Constants
Name | Return | Summary | |
---|---|---|---|
Page::statusHidden const | 1024 | Page is hidden and excluded from page finding methods unless overridden by selector (name: "hidden"). | |
Page::statusIncomplete const | 128 | ||
Page::statusLocked const | 4 | Indicates page is locked for changes (name: "locked") | |
Page::statusUnpublished const | 2048 | Page 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
.
Name | Return | Summary | |
---|---|---|---|
$page->getLanguageName() $page->getLanguageName() $page->getLanguageName($language = []) | array string | Get page name for language(s). If given a Language object, it returns a string. If given array of language names, or argument omitted, it returns an array like `[ 'default' => 'hello', 'es' => 'hola' ];`. @since 3.0.236 | |
$page->getLanguageStatus() $page->getLanguageStatus() $page->getLanguageStatus($language = []) | array bool | Get active status for language(s). If given a $language (Language or name of language) it returns a boolean. If given multiple language names (array), or argument omitted, it returns array like `[ 'default' => true, 'fr' => false ];`. @since 3.0.236 | |
$page->getLanguageValue() $page->getLanguageValue($language, $field) $page->getLanguageValue($language, $field) | mixed | Get value for field in language (requires LanguageSupport module). $language may be ID, language name or Language object. Field should be field name (string). | |
$page->getLanguageValues() $page->getLanguageValues($field) $page->getLanguageValues($field, array $langs = []) | array | Get values for field or one or more languages (requires LanguageSupport module). $field should be field/property name (string), $langs should be array of language names, or omit for all languages. Returns array of values indexed by language name. @since 3.0.236 | |
$page->getLanguages() $page->getLanguages() $page->getLanguages() | PageArray null | Get languages active for this page and viewable by current user | |
$page->localHttpUrl() $page->localHttpUrl() $page->localHttpUrl($language = null) | string | Return the page URL (including scheme and hostname) in the current user's language, or specify $language argument (Language object, name, or ID). | |
$page->localName() $page->localName() $page->localName($language = null, $useDefaultWhenEmpty = false) | string | Return 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() $page->localPath() $page->localPath($language = null) | string | Return the page path in the current user's language, or specify $language argument (Language object, name, or ID). | |
$page->localUrl() $page->localUrl() $page->localUrl($language = null) | string | Return the page URL in the current user's language, or specify $language argument (Language object, name, or ID). | |
$page->setLanguageName() $page->setLanguageName($language) $page->setLanguageName($language, $name = null) | Page | Set page name for language with `$page->setLanguageName('es', 'hola');` or set multiple with `$page->setLanguageName([ 'default' => 'hello', 'es' => 'hola' ]);` @since 3.0.236 | |
$page->setLanguageStatus() $page->setLanguageStatus($language) $page->setLanguageStatus($language, $status = null) | Page | Set active status for language(s), can be called as `$page->setLanguageStatus('es', true);` or `$page->setLanguageStatus([ 'es' => true, 'br' => false ]);` to set multiple. @since 3.0.236 | |
$page->setLanguageValue() $page->setLanguageValue($language, $field, $value) $page->setLanguageValue($language, $field, $value) | Page | Set value for field in language (requires LanguageSupport module). $language may be ID, language name or Language object. Field should be field name (string). | |
$page->setLanguageValues() $page->setLanguageValues($field, array $values) $page->setLanguageValues($field, array $values) | Page | Set value for field in one or more languages (requires LanguageSupport module). $field should be field/property name (string), $values should be array of values indexed by language name. @since 3.0.236 |
System
Most system properties directly correspond to columns in the pages
database table.
Name | Return | Summary | |
---|---|---|---|
$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->sortPrevious | int null | Previous sort order, if changed (3.0.235+) | |
$page->sortfield() $page->sortfield() $page->sortfield() | string | Return 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
Name | Return | Summary | |
---|---|---|---|
$page->count() $page->count() $page->count() | int | Returns number of children page has, affected by output formatting mode. | |
$page->draft() $page->draft() $page->draft($key = null, $value = null) | ProDraft int string Page array | Helper method for drafts (added by ProDrafts). | |
$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->getField() $page->getField($field) $page->getField($field) | Field null | Get a Field object in context or NULL if not valid for this page | |
$page->getFields() $page->getFields() $page->getFields() | FieldsArray | Returns a FieldsArray of all Field objects in the context of this Page | |
$page->getFormatted() $page->getFormatted(string $key) $page->getFormatted(string $key) | mixed | Get the formatted value of a field, regardless of output formatting state | |
$page->getInputfield() $page->getInputfield(string $fieldName) $page->getInputfield(string $fieldName) | Inputfield InputfieldWrapper null | Get a single Inputfield for the given field name | |
$page->getInputfields() $page->getInputfields() $page->getInputfields($fieldName = '') | null InputfieldWrapper | Return all Inputfield objects necessary to edit this page | |
$page->getIterator() $page->getIterator() $page->getIterator() | ArrayObject | Enables iteration of the page's properties and fields with PHP’s foreach() | |
$page->getMarkup() $page->getMarkup(string $key) $page->getMarkup(string $key) | string | Return the markup value for a given field name or {tag} string | |
$page->getText() $page->getText(string $key) $page->getText(string $key, bool $oneLine = false, $entities = null) | string | Same as getMarkup() except returned value is plain text | |
$page->getUnformatted() $page->getUnformatted(string $key) $page->getUnformatted(string $key) | mixed | Get the unformatted value of a field, regardless of current output formatting state | |
$page->hasField() $page->hasField($field) $page->hasField($field) | bool string | Returns whether or not given $field name, ID or object is valid for this Page | |
$page->isPublic() $page->isPublic() $page->isPublic() | bool | Is this page public and viewable by all? | |
$page->meta() $page->meta() $page->meta($key = '', $value = null) | WireDataDB string array int float | Get or set page’s persistent meta data | |
$page->outputFormatting | bool | Whether output formatting is enabled or not. | |
$page->setQuietly() $page->setQuietly(string $key, mixed $value) $page->setQuietly(string $key, mixed $value) | $this | Quietly set the value of a page property. | |
$page->setUnformatted() $page->setUnformatted(string $key, mixed $value) $page->setUnformatted(string $key, mixed $value) | self | Set the unformatted value of a field, regardless of current output formatting state |
For hooks
These methods are only useful for hooking and should not be called directly.
Name | Return | Summary | |
---|---|---|---|
$page->callUnknown() $page->callUnknown(string $method, array $arguments) $page->callUnknown(string $method, array $arguments) | null mixed | If method call resulted in no handler, this hookable method is called. | |
$page->edit() $page->edit() $page->edit($key = null, $markup = null, $modal = null) | string bool mixed | Get front-end editable output for field (requires PageFrontEdit module to be installed) | |
$page->getUnknown() $page->getUnknown(string $key) $page->getUnknown(string $key) | null mixed | Hookable method called when a request to a field was made that didn't match anything | |
$page->loaded() $page->loaded() $page->loaded() | (nothing) | For hooks to listen to, triggered when page is loaded and ready |
Urls
Name | Return | Summary | |
---|---|---|---|
$page->addUrl() $page->addUrl($url) $page->addUrl($url, $language = null) | bool | Add a new URL that redirects to this page and save immediately (returns false if already taken). | |
$page->editUrl() $page->editUrl() $page->editUrl($options = []) | string | Return the URL necessary to edit this page Can also be used as property: $page->editUrl | |
$page->httpUrl() $page->httpUrl() $page->httpUrl(array $options = []) | string | Returns the URL to the page, including scheme and hostname Can also be used as property: $page->httpUrl | |
$page->localHttpUrl() $page->localHttpUrl() $page->localHttpUrl($language = null) | string | Return the page URL (including scheme and hostname) in the current user's language, or specify $language argument (Language object, name, or ID). | |
$page->localPath() $page->localPath() $page->localPath($language = null) | string | Return the page path in the current user's language, or specify $language argument (Language object, name, or ID). | |
$page->localUrl() $page->localUrl() $page->localUrl($language = null) | string | Return the page URL in the current user's language, or specify $language argument (Language object, name, or ID). | |
$page->path() $page->path() $page->path() | string | Returns the Page’s path from the ProcessWire installation root. Can also be used as property: $page->path | |
$page->removeUrl() $page->removeUrl($url) $page->removeUrl($url) | bool | Remove a URL that redirects to this page and save immediately. | |
$page->url() $page->url() $page->url($options = null) | string | Returns the URL to the page (optionally with additional $options) Can also be used as property: $page->url | |
$page->urls() $page->urls() $page->urls(array $options = []) | array | Return all URLs that this page can be accessed from (excluding URL segments and pagination) Can also be used as property: $page->urls |
Files
Name | Return | Summary | |
---|---|---|---|
$page->filesManager() $page->filesManager() $page->filesManager() | PagefilesManager | Return instance of PagefilesManager specific to this Page Can also be used as property: $page->filesManager | |
$page->filesPath() $page->filesPath() $page->filesPath() | string | Returns the path for files, creating it if it does not yet exist Can also be used as property: $page->filesPath | |
$page->filesUrl() $page->filesUrl() $page->filesUrl() | string | Returns the URL for files, creating it if it does not yet exist Can also be used as property: $page->filesUrl | |
$page->hasFiles() $page->hasFiles() $page->hasFiles() | bool | Does the page have a files path and one or more files present in it? Can also be used as property: $page->hasFiles | |
$page->hasFilesPath() $page->hasFilesPath() $page->hasFilesPath() | bool | Does the page have a files path for storing files? | |
$page->secureFiles() $page->secureFiles() $page->secureFiles() | bool null | Does this Page use secure Pagefiles? |
Previous
Provides access to the previously set runtime value of some Page properties.
Name | Return | Summary | |
---|---|---|---|
$page->namePrevious | string null | Previous name, if changed. Null or blank string if not. | |
$page->parentPrevious | Page null | Previous parent, if parent was changed. Null if not. | |
$page->statusPrevious | int null | Previous status, if status was changed. Null if not. | |
$page->templatePrevious | Template null | Previous template, if template was changed. Null if not. |
Users
Name | Return | Summary | |
---|---|---|---|
$page->createdUser | User NullPage | The user that created this page. Returns a User or a NullPage. | |
$page->created_users_id | int | ID of created user. | |
$page->modifiedUser | User NullPage | The user that last modified this page. Returns a User or a NullPage. | |
$page->modified_users_id | int | ID of last modified user. |
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.236