Template is a Page’s connection to fields (via a Fieldgroup), access control, and output via a template file.

Template objects also maintain several properties which can affect the render behavior of pages using it.

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

Identification / Manipulation / Family / URLs / Access / Files / Cache / Page editor / Behaviors / Other / Common / Fields

Show “Template”             Show Arguments        


Template::flags int Flags (bitmask) assigned to this template. See the flag constants.
stringReturn the icon name used by this template
stringReturn template label for current language, or specified language if provided
PageArray, Languages or nullGet languages allowed for this template or null if language support not active.
intReturn the number of pages used by this template.
Template::id int Numeric database ID.
Template::label string Optional short text label to describe Template.
Template::name string Name of template.
Template::ns string Namespace found in the template file, or blank if not determined.
Template::pageClass string Class for instantiated page objects. Page assumed if blank, or specify class name.
Template::setIcon(string $icon)
$thisSet the icon to use with this template


Template or boolSave the template to database
Template::setFieldgroup(Fieldgroup $fieldgroup)
$thisSet this Template's Fieldgroup
(nothing)Set roles for this template


Template::childNameFormat string Name format for child pages. when specified, the page-add UI step can be skipped when adding children. Counter appended till unique. Date format assumed if any non-pageName chars present. Use 'title' to pull from title field.
Template::childTemplates array Array of template IDs that are allowed for children. Blank array indicates "any".
Page, NullPage or nullReturn the parent page that this template assumes new pages are added to .
PageArrayReturn all possible parent pages for this template
Template::noChildren int Set to 1 to cancel use of childTemplates.
Template::noParents int Set to 1 to cancel use of parentTemplates, set to -1 to only allow one page using this template to exist.
Template::parentTemplates array Array of template IDs that are allowed for parents. Blank array indicates "any".
Template::sortfield string Field that children of templates using this page should sort by (leave blank to let page decide, or specify "sort" for manual drag-n-drop).


Template::allowPageNum int Allow page numbers in URLs? (0=no, 1=yes)
Template::https int Use https? (0 = http or https, 1 = https only, -1 = http only)
Template::slashPageNum string or int Should PageNum segments have a trailing slash? (blank=either, 1=yes, 0=no) applies only if allowPageNum!=0.
Template::slashUrlSegments string or int Should last URL segment have a trailing slash? (blank=either, 1=yes, 0=no) applies only if urlSegments!=0.
Template::slashUrls int Page URLs should have a trailing slash? 1 = yes, 0 = no
array or intGet or set allowed URL segments
Can also be used as property: Template::urlSegments


Template::addRoles array Array of Role IDs that may add pages using this template.
Template::createRoles array Array of Role IDs that may create pages using this template.
Template::editRoles array Array of Role IDs that may edit pages using this template.
PageArrayGet the role pages that are part of this template
Template::guestSearchable int Pages appear in search results even when user doesnt have access? (0=no, 1=yes)
boolDoes this template have the given Role?
Template::noInherit int Disable role inheritance? Specify 1 to prevent edit/create/add access from inheriting to children, or 0 for default inherit behavior.
Template::redirectLogin int Redirect when no access: 0 = 404, 1 = login page, url = URL to redirect to.
Template::roles PageArray Roles assigned to this template for view access.
Template::rolesPermissions array Override permissions: Array indexed by role ID with values as permission ID (add) or negative permission ID (revoke).
(nothing)Set roles for this template
Template::useRoles int or bool Whether or not this template defines access.


Template::altFilename string Alternate filename for template file, if not based on template name.
Template::appendFile string File to append to template file (separate from $config->appendTemplateFile).
Template::contentType string Content-type header or index (extension) of content type header from $config->contentTypes
stringReturn corresponding template filename, including path
Can also be used as property: Template::filename
stringDoes the template filename exist?
Template::noAppendTemplateFile int or bool Disabe automatic append of $config->appendTemplateFile (if in use).
Template::noPrependTemplateFile int or bool Disable automatic prepend of $config->prependTemplateFile (if in use).
Template::prependFile string File to prepend to template file (separate from $config->prependTemplateFile).


Template::cacheExpire int Expire the cache for all pages when page using this template is saved? (1 = yes, 0 = no- only current page)
Template::cacheExpirePages array Array of Page IDs that should be expired, when cacheExpire == Template::cacheExpireSpecific
Template::cacheExpireSelector string Selector string matching pages that should be expired, when cacheExpire == Template::cacheExpireSelector
Template::cacheTime int Number of seconds pages using this template should cache for, or 0 for no cache. Negative values indicates setting used for external caching engine like ProCache.
Template::noCacheGetVars string GET vars that trigger disabling the cache (only when cache_time > 0)
Template::noCachePostVars string POST vars that trigger disabling the cache (only when cache_time > 0)
Template::useCacheForUsers int Use cache for: 0 = only guest users, 1 = guests and logged in users

Page editor

Template::errorAction int Action to take when published page missing required field is saved (0=notify only, 1=restore prev value, 2=unpublish page)
stringReturn the overriden "page name" label, or blank if not overridden
Template::getTabLabel(string $tab)
stringReturn page tab label for current language (or specified language if provided)
Template::nameContentTab int Pages should display the name field on the content tab? (0=no, 1=yes)
Template::nameLabel string Optional replacement for the default "Name" label on pages using this template
Template::tabChildren string Optional replacement for default "Children" label
Template::tabContent string Optional replacement for default "Content" label


Template::allowChangeUser int Allow the createdUser/created_users_id field of pages to be changed? (with API or in admin w/superuser only). 0=no, 1=yes
Template::noChangeTemplate int Don't allow pages using this template to change their template? (0=template change allowed, 1=template change not allowed)
Template::noGlobal int Template should ignore the global option of fields? (0=no, 1=yes)
Template::noLang int Disable multi-language for this template (when language support active).
Template::noMove int Pages using this template are not moveable? (0=moveable, 1=not movable)
Template::noSettings int Don't show a settings tab on pages using this template? (0=use settings tab, 1=no settings tab)
Template::noShortcut int Don't allow pages using this template to appear in shortcut "add new page" menu.
Template::noTrash int Pages using this template may not go in trash? (i.e. they will be deleted not trashed) (0=trashable, 1=not trashable)
Template::noUnpublish int Don't allow pages using this template to ever exist in an unpublished state - if page exists, it must be published. (0=page may be unpublished, 1=page may not be unpublished)


Template::compile int Set to 1 to enable compilation, 2 to compile file and included files, 3 for auto, or 0 to disable.
Template::pageLabelField string CSV or space separated string of field names to be displayed by ProcessPageList (overrides those set with ProcessPageList config).
Template::tags string Optional tags that can group this template with others in the admin templates list.


Template::addPermissionByRole($permission, $role)
boolAdd a permission that applies to users having a specific role with pages using this template
$thisAdd a Role to this template for view, edit, create, or add permission
Template::modified int Last modified time for template or template file
$thisRemove a Role to this template for view, edit, create, or add permission
Template::revokePermissionByRole($permission, $role)
boolRevoke a permission that applies to users having a specific role with pages using this template


Template::fieldgroup Fieldgroup The Fieldgroup used by the template. Can also be used to iterate a Template's fields.
Template::fieldgroupPrevious Fieldgroup or null Previous fieldgroup, if it was changed. Null if not.
boolDoes this template have the given Field?
Template::setFieldgroup(Fieldgroup $fieldgroup)
$thisSet this Template's Fieldgroup

Additional methods and properties

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

API reference based on ProcessWire core version 3.0.115