PagesNames::pageNameFromFormat() 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 childNameFormat property (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:

  • title Build name based on “title” field.
  • field Build name based on any other field name you choose, replace “field” with any field name.
  • text Text already in the right format (that’s not a field name) will be used literally, replace “text” with your text.
  • random Randomly generates a name.
  • untitled Uses an auto-incremented “untitled” name.
  • untitled-time Uses an “untitled” name followed by date/time number string.
  • a|b|c Builds 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-i Builds name from current date - replace “Y-m-d-H-i” with desired wireDate() format.
  • string with space A 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 = $pagesNames->pageNameFromFormat(Page $page);

// usage with all arguments
$string = $pagesNames->pageNameFromFormat(Page $page, $format = '', array $options = []);

Arguments

NameType(s)Description
pagePage
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.

  • language (Language|string): Language to use
  • format (string): Optional format to use, if $options were specified in $format argument.

Return value

string


PagesNames methods and properties

API reference based on ProcessWire core version 3.0.244

Latest news

  • ProcessWire Weekly #560
    In the 560th issue of ProcessWire Weekly we'll check out the latest core updates, cover newly released ProcessWire modules, and more. Read on!
    Weekly.pw / 1 February 2025
  • ProcessWire 3.0.244 new main/master version
    ProcessWire 3.0.244 is our newest main/master/stable version. It's been more than a year in the making and is packed with tons of new features, issue fixes, optimizations and more. This post covers all the details.
    Blog / 18 January 2025
  • 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.