Template
A Template connects a set of fields (via a Fieldgroup) to pages, determines how those pages are rendered (via a template file in /site/templates/), and controls URL behavior, access control, caching, and editor behavior
Template objects are retrieved from the $templates API variable:
$template = $templates->get('basic-page');See also Templates / $templates API.md file, or Templates documentation for creating, saving, deleting, and cloning templates.
| Property | Type | Description |
|---|---|---|
id | int | Numeric database ID |
name | string | Template name (also used as the template filename base) |
label | string | Optional admin label |
flags | int | Bitmask of Template::flag* constants |
modified | int | Unix timestamp of last modification to template or file |
ns | string | PHP namespace detected in the template file |
pageClass | string | Custom Page class for pages using this template; blank means Page |
pageLabelField | string | Field name(s) or markup displayed in the page list; may also embed an icon |
$template->getLabel($language)
Return the template label for the current (or specified) language. Falls back to
$template->name when no label is set.
- Arguments:
getLabel(Language|string|int|null $language = null) - Returns:
string
echo $template->getLabel(); // current language label or template name
echo $template->getLabel('spanish'); $template->setLabel($label, $language)
Set the template label for the default (or specified) language.
- Arguments:
setLabel(string $label, Language|string|int|null $language = null) - Returns:
self - Note: If no language is specified, the language named
defaultis used.
$template->setLabel('Basic Page'); // default language (not necessarily current)
$template->setLabel('Página básica', 'spanish'); $template->getIcon($prefix)
Return the icon name used by this template, as stored in pageLabelField.
- Arguments:
getIcon(bool $prefix = false) - Returns:
string— FontAwesome icon name withoutfa-prefix by default
$icon = $template->getIcon(); // e.g. "star"
$icon = $template->getIcon(true); // e.g. "fa-star"$template->setIcon($icon)
Set the icon for this template. The icon is stored as part of pageLabelField.
- Arguments:
setIcon(string $icon) - Returns:
$this
$template->setIcon('star'); // font-awesome icon name
$template->save();$template->getNumPages()
Return the number of pages using this template.
- Returns:
int
echo $template->getNumPages();$template->getPageClass($withNamespace)
Get the PHP class name used for pages with this template. May differ from $template->pageClass
when a custom class is auto-detected at runtime (e.g. BlogPostPage for template blog-post).
- Arguments:
getPageClass(bool $withNamespace = true) - Returns:
string - Available 3.0.152.
$class = $template->getPageClass(); // e.g. "ProcessWire\BlogPostPage"
$class = $template->getPageClass(false); // e.g. "BlogPostPage"To create a page class that the template will use:
- Ensure that
$config->usePageClasses = true;in/site/config.php. - Create a PHP class file in
/site/classes/using the template name in Pascal Case followed by the wordPage, e.g. templateblog-postwould useBlogPostPage.php - Create the class in the file you created above:
<?php namespace ProcessWire; class BlogPostPage extends Page {} - Pages using the template
blog-postwill now use classBlogPostPagerather thanPage.
$template->editUrl($http)
Return the admin URL to edit this template's settings.
- Arguments:
editUrl(bool $http = false) - Returns:
string
echo $template->editUrl(); // /processwire/setup/template/edit?id=12A Template always has exactly one Fieldgroup. Accessing $template->fieldgroup (or
the alias $template->fields) gives you the Fieldgroup, which you can iterate to
access the template's fields.
// Iterate fields in this template
foreach($template->fieldgroup as $field) {
echo $field->name . "\n";
}
// Check if template has a specific field
if($template->hasField('body')) {
$field = $template->fieldgroup->getField('body');
}$template->hasField($name)
Return true if this template's fieldgroup contains the given field.
- Arguments:
hasField(Field|string|int $name) - Returns:
bool
$template->setFieldgroup($fieldgroup)
Assign a different Fieldgroup to this template. Save the template afterward to persist.
Throws a WireException if the template is a system template or has permanent fields.
- Arguments:
setFieldgroup(Fieldgroup $fieldgroup) - Returns:
$this
$template->setFieldgroup($fieldgroups->get('other-fieldgroup'));
$template->save();This is rarely used in practice as most templates have a matching (by name) fieldgroup.
Access control is enabled per-template by setting $template->useRoles = 1 and then
assigning roles. When useRoles is 0 (the default), the template inherits access from
the closest parent page with a template that defines access control.
| Property | Type | Description |
|---|---|---|
useRoles | int\|bool | Enable role-based access control for this template (0=no, 1=yes) |
roles | PageArray | Roles with page-view access (PageArray of Role objects) |
editRoles | array | Role IDs that may edit pages |
addRoles | array | Role IDs that may add children to pages |
createRoles | array | Role IDs that may create new pages |
rolesPermissions | array | Per-role permission overrides: [roleId => [permId, -permId, ...]] where positive ID adds, negative ID removes |
noInherit | int | Prevent edit/add/create access from inheriting to non-access-controlled children (0=inherit, 1=no inherit) |
redirectLogin | int | Behavior on access denied: 0=404, 1=login page, or page ID/URL to redirect to |
guestSearchable | int | Pages appear in search results even when guest has no view access (0=no, 1=yes) |
$template->getRoles($type)
Return a PageArray of roles assigned to this template for the given access type.
- Arguments:
getRoles(string $type = 'view') - Returns:
PageArray $typemay be'view'(default),'edit','create', or'add'.
$viewRoles = $template->getRoles(); // view roles
$editRoles = $template->getRoles('edit');$template->hasRole($role, $type)
Return true if this template has the given role for the specified access type.
- Arguments:
hasRole(Role|string|int $role, string $type = 'view') - Returns:
bool
if($template->hasRole('guest')) {
// guest can view pages using this template
}
if($template->hasRole('editor', 'edit')) {
// editors can edit
}$template->addRole($role, $type)
Add a role to this template for the given access type. Save the template afterward.
- Arguments:
addRole(Role|int|string $role, string $type = 'view') - Returns:
$this
$template->addRole('guest'); // add view access for guest
$template->addRole('editor', 'edit'); // add edit access for editor
$template->save();$template->removeRole($role, $type)
Remove a role from this template for the given access type. Specify 'all' for $type
to remove the role from every access type at once.
- Arguments:
removeRole(Role|int|string $role, string $type = 'view') - Returns:
$this
$template->removeRole('editor', 'edit');
$template->removeRole('old-role', 'all'); // remove from all access types
$template->save();$template->addPermissionByRole($permission, $role, $test)
Add a permission override that applies to users with a specific role on pages using
this template. Does not affect access to the page-view or page-edit permissions
managed through addRole()/removeRole() — this is for custom permission overrides.
- Arguments:
addPermissionByRole(Permission|int|string $permission, Role|int|string $role, bool $test = false) - Returns:
bool—trueif an update was (or would be) made,falseif not. - Specify
truefor$testto only test if an update would be made (see return value), without changing anything.
$template->addPermissionByRole('page-publish', 'editor');
$template->save();$template->revokePermissionByRole($permission, $role, $test)
Revoke a permission for users with a specific role.
- Arguments:
revokePermissionByRole(Permission|int|string $permission, Role|int|string $role, bool $test = false) - Returns:
bool - Specify
truefor$testto only test if an update would be made (see return value), without changing anything.
Family settings control the parent/child relationships between pages.
| Property | Type | Description |
|---|---|---|
noChildren | int | Prevent child pages (0=children allowed, 1=no children) |
noParents | int | 0=any parent, 1=no new pages, -1=only one page of this template may exist |
childTemplates | int[] | IDs of templates allowed for children; empty array = any |
parentTemplates | int[] | IDs of templates allowed for parents; empty array = any |
sortfield | string | Field name to sort children by; blank = page decides; sort = manual |
childNameFormat | string | Auto-name format for new child pages (date format or title or counter) |
$template->childTemplates($setValue)
Get or set the templates allowed for children of pages using this template.
- Arguments:
childTemplates(array|TemplatesArray|null $setValue = null) - Returns:
TemplatesArray - Applies only if the
noChildrensetting is0(children allowed). - Available 3.0.153.
// Get child templates
$allowed = $template->childTemplates();
foreach($allowed as $t) echo $t->name . "\n";
// Set child templates (by name, ID, or Template object)
$template->childTemplates(['blog-post', 'event']);
$template->save();
// Allow any template for children (clear restrictions)
$template->childTemplates([]);
$template->save();$template->parentTemplates($setValue)
Get or set the templates allowed for parents of pages using this template.
- Arguments:
parentTemplates(array|TemplatesArray|null $setValue = null) - Returns:
TemplatesArray - Applies only if the
noParentssetting is0or-1. - Available 3.0.153.
$template->parentTemplates(['blog']); // only pages with 'blog' template may be parents
$template->save();$template->allowNewPages()
Return true if new pages using this template may be created, based on noParents.
- Returns:
bool
if($template->allowNewPages()) {
// safe to create a new page with this template
}$template->getParentPage($checkAccess)
Return the defined parent page for new pages using this template (based on family
settings). Returns null if no parent is defined, NullPage if multiple parents match.
- Arguments:
getParentPage(bool $checkAccess = false) - Returns:
Page|NullPage|null
$parent = $template->getParentPage();
if($parent && $parent->id) {
echo "New pages go under: $parent->path";
}$template->getParentPages($checkAccess)
Return all defined parent pages for this template.
- Arguments:
getParentPages(bool $checkAccess = false) - Returns:
PageArray
| Property | Type | Description |
|---|---|---|
allowPageNum | int | Allow page number URL segments (0=no, 1=yes) |
urlSegments | int\|array | Allow URL segments: 0=no, 1=any, or array of allowed segment strings |
https | int | HTTPS enforcement: 0=either, 1=HTTPS only, -1=HTTP only |
slashUrls | int | Trailing slash on page URLs (1=yes, 0=no) |
slashPageNum | int\|string | Trailing slash on page number segments (0=either, 1=yes, -1=no) |
slashUrlSegments | int\|string | Trailing slash on last URL segment (0=either, 1=yes, -1=no) |
$template->urlSegments($value)
Get or set the URL segments setting.
- Arguments:
urlSegments(array|int|bool|string $value = '~') - Returns:
array|int— array of specific allowed segments, or0if disabled, or1if any allowed - Omit the argument to get the current value.
- Pass an array of specific allowed segments,
true/1to allow all, or0/falseto disable. - Segment strings may be literal or include
'regex:your-pattern'entries.
// Allow any URL segments
$template->urlSegments(1);
// Only allow specific segments
$template->urlSegments(['archive', 'feed', 'regex:[0-9]{4}']);
// Disable URL segments
$template->urlSegments(0);
$template->save();$template->isValidUrlSegmentStr($urlSegmentStr)
Check whether a URL segment string is valid for this template's settings.
- Arguments:
isValidUrlSegmentStr(string $urlSegmentStr) - Returns:
bool - Available 3.0.186.
if($template->isValidUrlSegmentStr('foo/bar/baz')) {
// URL segment string is permitted
}| Property | Type | Description |
|---|---|---|
filename | string | Full path to the template file (auto-generated from name) |
altFilename | string | Alternate filename if not based on template name |
contentType | string | Content-type header or key from $config->contentTypes |
noPrependTemplateFile | int | Disable auto-prepend of $config->prependTemplateFile (0=use, 1=skip) |
noAppendTemplateFile | int | Disable auto-append of $config->appendTemplateFile (0=use, 1=skip) |
prependFile | string | File to prepend (relative to /site/templates/) |
appendFile | string | File to append (relative to /site/templates/) |
pagefileSecure | int | Secure file serving: 0=off, 1=yes for non-public pages, 2=always |
$template->filename($filename)
Get or set the template filename. When getting, it auto-generates the path from the template name if not already set, and also detects file modifications and namespace.
- Arguments:
filename(string|null $filename = null) - Returns:
string— full path to the template file - You may pass a basename (e.g.
'home.php') or a full path. Available for setting 3.0.143.
$file = $template->filename(); // full path, e.g. /site/templates/basic-page.php
$template->filename('custom-file.php'); // use /site/templates/custom-file.php$template->filenameExists()
Return true if the template file exists on disk.
- Returns:
bool
if($template->filenameExists()) {
// template has a PHP file
}Template caching stores rendered page output for a specified time. A cacheTime of 0
disables caching. Negative values are reserved for external caching engines (e.g. ProCache).
| Property | Type | Description |
|---|---|---|
cacheTime | int | Seconds to cache page output; 0=disabled; negative=external cache |
useCacheForUsers | int | 0=guest users only, 1=all users |
noCacheGetVars | string | Space-separated GET vars that bypass the cache |
noCachePostVars | string | Space-separated POST vars that bypass the cache |
cacheExpire | int | How to expire the cache when a page is saved — see Template::cacheExpire* constants |
cacheExpirePages | array | Page IDs to expire when cacheExpire === Template::cacheExpireSpecific |
cacheExpireSelector | string | Selector matching pages to expire when cacheExpire === Template::cacheExpireSelector |
Cache expiration constants
| Constant | Value | Description |
|---|---|---|
Template::cacheExpirePage | 0 | Expire only the saved page |
Template::cacheExpireSite | 1 | Expire the entire site cache |
Template::cacheExpireParents | 2 | Expire the saved page and its parents |
Template::cacheExpireSpecific | 3 | Expire specific pages listed in cacheExpirePages |
Template::cacheExpireSelector | 4 | Expire pages matching cacheExpireSelector |
Template::cacheExpireNone | -1 | Do not expire anything on save |
$template->cacheTime = 3600; // cache for 1 hour
$template->useCacheForUsers = 1; // cache for all users
$template->cacheExpire = Template::cacheExpireSite; // expire full cache on save
$template->save();For a more complete page caching solution see ProCache.
Boolean-style settings that govern page behavior. All are 0 (off) by default unless
noted.
| Property | Description |
|---|---|
noGlobal | Ignore the global flag on fields (0=respect global, 1=ignore) |
noMove | Prevent pages from being moved to a different parent |
noTrash | Prevent pages from being trashed (they are deleted instead) |
noChangeTemplate | Prevent pages from changing their template |
noUnpublish | Prevent pages from existing in an unpublished state |
noShortcut | Hide this template from the "Add new page" shortcut menu |
noLang | Disable multi-language support for pages using this template |
allowChangeUser | Allow the createdUser field to be changed via API or admin (superuser only) |
compile | PHP compilation: 0=off, 1=file only, 2=file+includes, 3=auto (default=3) |
$template->noTrash = 1; // pages using this template cannot be trashed
$template->noMove = 1; // pages cannot be moved
$template->noLang = 1; // single-language only, even if LanguageSupport active
$template->save();Note: the compile option applies only if $config->templateCompile is true.
Settings that affect the admin page editor for pages using this template.
| Property | Type | Description |
|---|---|---|
nameContentTab | int | Show the page name field on the Content tab (0=no, 1=yes) |
tabContent | string | Override label for the Content tab |
tabChildren | string | Override label for the Children tab |
nameLabel | string | Override label for the "Name" field |
errorAction | int | Action when a required field is empty on a published page save: 0=notify, 1=restore previous, 2=unpublish |
$template->getTabLabel($tab, $language)
Return the overridden label for a page editor tab, or blank if not overridden.
- Arguments:
getTabLabel(string $tab, Language|string|int|null $language = null) - Returns:
string $tabshould be'content'or'children'.
$label = $template->getTabLabel('content'); // blank if not overridden$template->setTabLabel($tab, $label, $language)
Set label for a page editor tab, optionally for a specific language.
- Arguments:
setTabLabel(string $tab, string $label, Language|string|int|null $language = null) - Returns:
self $tabshould be'content'or'children'.
$template->setTabLabel('content', 'Main');$template->getNameLabel($language)
Return the overridden page name input label, or blank if not overridden.
- Arguments:
getNameLabel(Language|string|int|null $language = null) - Returns:
string
$template->setNameLabel($label, $language)
Set the page name input label, optionally for a specific language.
- Arguments:
setNameLabel(string $label, Language|string|int|null $language = null) - Returns:
self
Tags are space-separated strings stored in $template->tags. They are used to group
templates in the admin template list.
$template->getTags()
Return the template's tags as an associative array keyed and valued by tag name.
- Returns:
array—[tagName => tagName, ...]
$tags = $template->getTags(); // ['marketing' => 'marketing', 'blog' => 'blog']$template->hasTag($tag)
Return true if this template has the given tag.
- Arguments:
hasTag(string $tag) - Returns:
bool
$template->addTag($tag) / $template->removeTag($tag)
Add or remove a tag. Remember to save the template afterward.
- Returns:
$this
$template->addTag('marketing');
$template->removeTag('old-tag');
$template->save();$template->getLanguages()
Return a PageArray of languages allowed for pages using this template. Returns null
if LanguageSupport is not installed. When $template->noLang is set, returns only the
default language.
- Returns:
PageArray|Languages|null
$languages = $template->getLanguages();
if($languages) {
foreach($languages as $lang) echo $lang->name . "\n";
}$template->save()
Save this template to the database. Equivalent to $templates->save($template).
- Returns:
Template|false— returns the Template on success,falseon failure
$template->label = 'New Label';
$template->save();| Constant | Value | Description |
|---|---|---|
Template::flagSystem | 8 | Template is a system template; name/ID cannot be changed and it cannot be deleted |
Template::flagSystemOverride | 32768 | Temporary override for system flag — set first, then remove flagSystem in two steps |
To remove the system flag from a template:
$template->flags = $template->flags | Template::flagSystemOverride;
$template->flags = $template->flags & ~Template::flagSystem;
$template->flags = $template->flags & ~Template::flagSystemOverride;
$template->save();- Source file:
wire/core/Template/Template.php. $template->nameis used as the template filename base:basic-page→/site/templates/basic-page.php.$template->fieldgroupand$template->fieldsare aliases for the sameFieldgroupobject.$template->cacheTimeis a camelCase alias for the underlyingcache_timesetting.- The
noChildren,noParentsproperties may benull, a blank string or0when empty — check with(int)cast if comparing numerically. $template->__toString()returns$template->name, so templates in string context produce their name.
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
- Tags
- Properties
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 | |
Template::setLabel() Template::setLabel(string $label) Template::setLabel(string $label, $language = null) | $this | Set template label, optionally for a language |
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') | None | 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 Template | 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 defined 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') | None | 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 editor 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::setTabLabel() Template::setTabLabel(string $tab, string $label) Template::setTabLabel(string $tab, string $label, $language = null) | $this | Set a page editor tab label for default language (or specified language) | |
| 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. |
Properties
| Name | Return | Summary | |
|---|---|---|---|
| Template::modified | int | Last modified time for template or template file |
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.264