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
Name | Return | Summary | |
---|---|---|---|
Template::flags | int | Flags (bitmask) assigned to this template. See the flag constants. | |
Template::getIcon() Template::getIcon() Template::getIcon(bool $prefix = false) | string | Return the icon name used by this template | |
Template::getLabel() Template::getLabel() Template::getLabel($language = null) | string | Return template label for current language, or specified language if provided | |
Template::getLanguages() Template::getLanguages() Template::getLanguages() | PageArray Languages null | Get languages allowed for this template or null if language support not active. | |
Template::getNumPages() Template::getNumPages() Template::getNumPages() | int | Return the number of pages used by this template. | |
Template::getPageClass() Template::getPageClass() Template::getPageClass(bool $withNamespace = true) | string | Get class name to use for Page objects using 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() Template::setIcon(string $icon) Template::setIcon(string $icon) | $this | Set the icon to use with this template |
Manipulation
Name | Return | Summary | |
---|---|---|---|
Template::save() Template::save() Template::save() | Template bool | Save the template to database | |
Template::setFieldgroup() Template::setFieldgroup(Fieldgroup $fieldgroup) Template::setFieldgroup(Fieldgroup $fieldgroup) | $this | Set this Template's Fieldgroup | |
Template::setRoles() Template::setRoles($value) Template::setRoles($value, string $type = 'view') | (nothing) | Set roles for this template |
Family
Name | Return | Summary | |
---|---|---|---|
Template::allowNewPages() Template::allowNewPages() Template::allowNewPages() | bool | Allow new pages that use 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() Template::childTemplates() Template::childTemplates($setValue = null) | TemplatesArray | Get or set child templates (templates allowed for children of pages using this template) Can also be used as property: Template::childTemplates | |
Template::getParentPage() Template::getParentPage() Template::getParentPage(bool $checkAccess = false) | Page NullPage null | Return the parent page that this template assumes new pages are added to | |
Template::getParentPages() Template::getParentPages() Template::getParentPages(bool $checkAccess = false) | PageArray | Return 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() Template::parentTemplates() Template::parentTemplates($setValue = null) | TemplatesArray | Get or set parent templates (templates allowed for parent pages of pages using this template) Can also be used as property: Template::parentTemplates | |
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). |
URLs
Name | Return | Summary | |
---|---|---|---|
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::isValidUrlSegmentStr() Template::isValidUrlSegmentStr(string $urlSegmentStr) Template::isValidUrlSegmentStr(string $urlSegmentStr) | bool | Is the given URL segment string allowed according to this template’s settings? | |
Template::slashPageNum | string int | Should PageNum segments have a trailing slash? (0=either, 1=yes, -1=no) applies only if allowPageNum!=0. | |
Template::slashUrlSegments | string int | Should last URL segment have a trailing slash? (0=either, 1=yes, -1=no) applies only if urlSegments!=0. | |
Template::slashUrls | int | Page URLs should have a trailing slash? 1 = yes, 0 = no | |
Template::urlSegments() Template::urlSegments() Template::urlSegments($value = '~') | array int | Get or set allowed URL segments Can also be used as property: Template::urlSegments |
Access
Name | Return | Summary | |
---|---|---|---|
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. | |
Template::getRoles() Template::getRoles() Template::getRoles(string $type = 'view') | PageArray | Get 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) | |
Template::hasRole() Template::hasRole($role) Template::hasRole($role, $type = 'view') | bool | Does 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, int(>1) = ID of page 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). | |
Template::setRoles() Template::setRoles($value) Template::setRoles($value, string $type = 'view') | (nothing) | Set roles for this template | |
Template::useRoles | int bool | Whether or not this template defines access. |
Files
Name | Return | Summary | |
---|---|---|---|
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 | |
Template::filename() Template::filename() Template::filename(string $filename = null) | string | Return corresponding template filename including path, or set template filename Can also be used as property: Template::filename | |
Template::filenameExists() Template::filenameExists() Template::filenameExists() | bool | Does the template filename exist? | |
Template::noAppendTemplateFile | int bool | Disabe automatic append of $config->appendTemplateFile (if in use). | |
Template::noPrependTemplateFile | int bool | Disable automatic prepend of $config->prependTemplateFile (if in use). | |
Template::pagefileSecure | int | Use secure pagefiles for pages using this template? 0=No/not set, 1=Yes (for non-public pages), 2=Always (3.0.166+) | |
Template::prependFile | string | File to prepend to template file (separate from $config->prependTemplateFile). |
Cache
Name | Return | Summary | |
---|---|---|---|
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
Name | Return | Summary | |
---|---|---|---|
Template::errorAction | int | Action to take when published page missing required field is saved (0=notify only, 1=restore prev value, 2=unpublish page) | |
Template::getNameLabel() Template::getNameLabel() Template::getNameLabel($language = null) | string | Return the overriden "page name" label, or blank if not overridden | |
Template::getTabLabel() Template::getTabLabel(string $tab) Template::getTabLabel(string $tab, $language = null) | string | Return 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 |
Behaviors
Name | Return | Summary | |
---|---|---|---|
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) |
Other
Name | Return | Summary | |
---|---|---|---|
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). |
Common
Fields
Name | Return | Summary | |
---|---|---|---|
Template::fieldgroup | Fieldgroup Field[] | The Fieldgroup used by the template. Can also be used to iterate a Template's fields. | |
Template::fieldgroupPrevious | Fieldgroup null | Previous fieldgroup, if it was changed. Null if not. | |
Template::hasField() Template::hasField($name) Template::hasField($name) | bool | Does this template have the given Field? | |
Template::setFieldgroup() Template::setFieldgroup(Fieldgroup $fieldgroup) Template::setFieldgroup(Fieldgroup $fieldgroup) | $this | Set this Template's Fieldgroup |
Tags
Name | Return | Summary | |
---|---|---|---|
Template::addTag() Template::addTag(string $tag) Template::addTag(string $tag) | $this | Add tag | |
Template::getTags() Template::getTags() Template::getTags() | array | Get tags array | |
Template::hasTag() Template::hasTag(string $tag) Template::hasTag(string $tag) | bool | Does this template have given tag? | |
Template::removeTag() Template::removeTag(string $tag) Template::removeTag(string $tag) | self | Remove tag | |
Template::tags | string | Optional tags that can group this template with others in the admin templates list. |
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.236