PagesNames::names method
Create a page name from the given format
- Returns a generated page name that is not yet assigned to the page.
- If no format is specified, it first falls back to page parent template
childNameFormatproperty (if present). - If no format can be determined, it falls back to a randomly generated page name.
- Does not check if page name is already in use.
Options for $format argument:
titleBuild name based on “title” field.fieldBuild name based on any other field name you choose, replace “field” with any field name.textText already in the right format (that’s not a field name) will be used literally, replace “text” with your text.randomRandomly generates a name.untitledUses an auto-incremented “untitled” name.untitled-timeUses an “untitled” name followed by date/time number string.a|b|cBuilds name from first matching field name, where a|b|c are your field names.{field}Builds name from the given field name.{a|b|c}Builds name first matching field name, where a|b|c would be replaced with your field names.date:Y-m-d-H-iBuilds name from current date - replace “Y-m-d-H-i” with desired wireDate() format.string with spaceA string that does not match one of the above and has space is assumed to be a wireDate() format.string with /A string that does not match one of the above and has a “/” slash is assumed to be a wireDate() format.
For formats above that accept a wireDate() format, see WireDateTime::date() method for format details. It accepts PHP
date() format, PHP strftime() format, as well as some other predefined options.
Usage
// basic usage
$string = $pages->names->pageNameFromFormat(Page $page);
// usage with all arguments
$string = $pages->names->pageNameFromFormat(Page $page, $format = '', array $options = []);Arguments
| Name | Type(s) | Description |
|---|---|---|
$page | Page | |
$format (optional) | string array | Optional format. If not specified, pulls from $page’s parent template. |
$options (optional) | array | Options to modify behavior. May also be specified in $format argument.
|
Return value
string
$pages->names methods and properties
API reference based on ProcessWire core version 3.0.253