Conditions
TSconfig TypoScript conditions offer a way to conditionally change TypoScript based on current context. See the TypoScript syntax condition chapter for the basic syntax of conditions.
It is possible to use TypoScript conditions in both user TSconfig and page TSconfig, just as it is done in frontend TypoScript. The list of available variables and functions is different, though.
The Symfony expression language tends to throw warnings when sub arrays are checked in a condition that do not exist. Use the traverse function to avoid this.
Condition variables available in TSconfig
applicationContext
applicationContext
-
- Type
- string
Current application context as string. See Application context.
Example: Condition applies in application context "Development"
[applicationContext == "Development"]
// Your settings go here
[END]
Example: Condition applies in any application context that does not start with "Production"
This condition applies in any context that is "Production" or starts with "Production" (for example Production/Staging"):
[applicationContext matches "/^Production/"]
// Your settings go here
[END]
page
page
-
- Type
- array
All data of the current page record as array. Only available in page TSconfig, not in user TSconfig.
Example: Condition applies only on certain pages
# Check single page uid
[traverse(page, "uid") == 2]
// Your settings go here
[END]
# Check list of page uids
[traverse(page, "uid") in [17,24]]
// Your settings go here
[END]
# Check list of page uids NOT in
[traverse(page, "uid") not in [17,24]]
// Your settings go here
[END]
# Check range of pages (example: page uid from 10 to 20)
[traverse(page, "uid") in 10..20]
// Your settings go here
[END]
# Check the page backend layout
[traverse(page, "backend_layout") == 5]
// Your settings go here
[END]
[traverse(page, "backend_layout") == "example_layout"]
// Your settings go here
[END]
# Check the page title
[traverse(page, "title") == "foo"]
// Your settings go here
[END]
tree
tree
-
- Type
- Object
Object with tree information. Only available in page TSconfig, not in user TSconfig.
tree.level
tree.level
-
- Type
- integer
Current tree level. Only available in page TSconfig, not in user TSconfig. Starts at
1
(root level).
Example: Condition applies on a page on root level
# Check if page is on level 1 (root):
[tree.level == 1]
// Your settings go here
[END]
Hint
In older versions before TYPO3 v10, this setting was available as
tree
variable.
That variable started the root level at value 0
, and now it starts at 1
.
Keep this in mind when migrating old conditions.
Unlike the frontend TypoScript condition tree.
, the backend tree level
is not affected by pages.
. This means, for nested sites it cannot
be used to match "site roots" or in general any n-th levels of page tree depths.
It's the absolute depth of the entire page tree, starting with 1
.
tree.pagelayout
tree.pagelayout
-
- Type
- integer / string
Check for the defined backend layout of a page including the inheritance of the field Backend Layout (subpages of this page). Only available in page TSconfig, not in user TSconfig.
Example: Condition applies on pages with a certain backend layout
# Use backend_layout records uids
[tree.pagelayout == 2]
// Your settings go here
[END]
# Use TSconfig provider of backend layouts
[tree.pagelayout == "pagets__Home"]
// Your settings go here
[END]
tree.rootLine
tree.rootLine
-
- Type
- array
An array of arrays with uid and pid. Only available in page TSconfig, not in user TSconfig.
Example: Condition applies on all subpages of page
[tree.rootLine[0]["uid"] == 1]
// Your settings go here
[END]
tree.rootLineIds
tree.rootLineIds
-
- Type
- array
An array with UIDs of the root line. Only available in page TSconfig, not in user TSconfig.
Example: Condition applies if a page is in the root line
# Check if page with uid 2 is inside the root line
[2 in tree.rootLineIds]
// Your settings go here
[END]
tree.rootLineParentIds
tree.rootLineParentIds
-
- Type
- array
An array with parent UIDs of the root line. Only available in page TSconfig, not in user TSconfig.
Example: Condition applies if a page's parent is in the root line
# Check if page with uid 2 is the parent of a page inside the root line
[2 in tree.rootLineParentIds]
// Your settings go here
[END]
backend
backend
-
- Type
- Object
Object with backend information.
backend.user
backend.user
-
- Type
- Object
Object with current backend user information.
backend.user.isAdmin
backend.user.isAdmin
-
- Type
- boolean
True if current user is admin.
Example: Condition applies if the current backend user is an admin
# Evaluates to true if current backend user is administrator
[backend.user.isAdmin]
// Your settings go here
[END]
backend.user.isLoggedIn
backend.user.isLoggedIn
-
- Type
- boolean
True if current user is logged in.
Example: Condition applies if any backend user is logged in
[backend.user.isLoggedIn]
// Your settings go here
[END]
backend.user.userId
backend.user.userId
-
- Type
- integer
UID of current user.
Example: Condition applies if a certain backend user is logged in
# Evaluates to true if user uid of current logged in backend user is equal to 5
[backend.user.userId == 5]
// Your settings go here
[END]
backend.user.userGroupIds
backend.user.userGroupList
-
- Type
- array
array of user group IDs of the current backend user.
Example: Condition applies if a backend user of a certain group is logged in
[2 in backend.user.userGroupIds]
// Your settings go here
[END]
backend.user.userGroupList
backend.user.userGroupList
-
- Type
- string
Comma list of group UIDs
Example: Condition applies if the groups of a user meet a certain pattern
[like(","~backend.user.userGroupList~",", "*,1,*")]
// Your settings go here
[END]
workspace
workspace
-
- Type
- Object
object with workspace information
workspace.workspaceId
.workspaceId
-
- Type
- integer
UID of current workspace.
Example: Condition applies only in a certain workspace
[workspace.workspaceId == 0]
// Your settings go here
[END]
workspace.isLive
workspace.isLive
-
- Type
- boolean
True if current workspace is live.
Example: Condition applies only in live workspace
[workspace.isLive]
// Your settings go here
[END]
workspace.isOffline
workspace.isOffline
-
- Type
- boolean
True if current workspace is offline
Example: Condition applies only in offline workspace
[workspace.isOffline]
// Your settings go here
[END]
typo3
typo3
-
- Type
- Object
Object with TYPO3 related information
typo3.version
typo3.version
-
- Type
- string
TYPO3 version (e.g. 12.4.0-dev)
Example: Condition only applies in an exact TYPO3 version like 12.4.0
[typo3.version == "12.4.0"]
// Your settings go here
[END]
typo3.branch
typo3.branch
-
- Type
- string
TYPO3 branch (e.g. 12.4)
Example: Condition applies in all TYPO3 versions of a branch like 12.4
[typo3.branch == "12.4"]
// Your settings go here
[END]
typo3.devIpMask
typo3.devIpMask
-
- Type
- string
Example: Condition only applies if the devIpMask is set to a certain value
[typo3.devIpMask == "203.0.113.6"]
// Your settings go here
[END]
Condition functions available in TSconfig
date()
date([parameter])
-
- Type
- integer
- Parameter
- [parameter]: string / integer
Get current date in given format. See PHP date function as reference for possible usage.
Example: Condition applies at certain dates or times
# True if day of current month is 7
[date("j") == 7]
// Your settings go here
[END]
# True if day of current week is 7
[date("w") == 7]
// Your settings go here
[END]
# True if day of current year is 7
[date("z") == 7]
// Your settings go here
[END]
# True if current hour is 7
[date("G") == 7]
// Your settings go here
[END]
like()
like([search-string], [pattern])
-
- Type
- boolean
- parameter
- [search-string] : string; [pattern]: string
This function has two parameters: The first parameter is the string to search in, the second parameter is the search string.
Example: Use the "like()" function in conditions
# Search a string with * within another string
[like("fooBarBaz", "*Bar*")]
// Your settings go here
[END]
# Search string with single characters in between, using ?
[like("fooBarBaz", "f?oBa?Baz")]
// Your settings go here
[END]
# Search string using regular expression
[like("fooBarBaz", "/f[o]{2,2}[aBrz]+/")]
// Your settings go here
[END]
traverse()
traverse([array], [key])
-
- Type
- any
- Parameter
- [array]: array; [key]: string or integer
This function gets a value from an array with arbitrary depth and suppresses PHP warning when sub arrays do not exist. It has two parameters: The first parameter is the array to traverse, the second parameter is the path to traverse.
In case the path is not found in the array, an empty string is returned.
Example: Condition applies if request parameter matches a certain value
# Traverse query parameters of current request along tx_news_pi1[news]
[traverse(request.getQueryParams(), 'tx_news_pi1/news') > 0]
// Your settings go here
[END]
compatVersion()
compatVersion([version-pattern])
-
- Type
- boolean
- Parameter
- [version-pattern]: string
Compares against the current TYPO3 branch.
Example: Condition applies if the current TYPO3 version matches a pattern
# True if current version is 12.4.x
[compatVersion("12.4")]
// Your settings go here
[END]
[compatVersion("12.4.0")]
// Your settings go here
[END]
[compatVersion("12.4.1")]
// Your settings go here
[END]
getenv()
getenv([enviroment_variable])
-
- Type
- string
- Parameter
- [enviroment_variable]: string
PHP function getenv.
Example: Condition applies if the virtual host is set to a certain value
[getenv("VIRTUAL_HOST") == "www.example.org"]
// Your settings go here
[END]
feature()
feature([feature_key])
-
- Type
- any
- Parameter
- [feature_key]: string
Provides access to feature toggles current state.
Example: condition applies if a feature toggle is enabled
# True if feature toggle for strict TypoScript syntax is enabled:
[feature("TypoScript.strictSyntax") === false]
// Your settings go here
[END]
site()
site([keyword])
-
- Type
- string
- Parameter
- [keyword]: string
Get value from site configuration, or null if no site was found or property does not exists. Only available in page TSconfig, not available in user TSconfig. Available Information:
- site("identifier")
- Returns the identifier of current site as string.
- site("base")
- Returns the base of current site as string.
- site("rootPageId")
- Returns the root page uid of current site as integer.
- site("languages")
- Returns array of available languages for current site. For deeper information, see siteLanguage().
- site("allLanguages")
- Returns array of available and unavailable languages for current site. For deeper information, see siteLanguage().
- site("defaultLanguage")
- Returns the default language for current site. For deeper information, see siteLanguage().
- site("configuration")
- Returns an array with all available configuration for current site.
Example: Condition applies if a certain value is set in the site configuration
# Site identifier
[site("identifier") == "my_website"]
// Your settings go here
[END]
# Match site base host
[site("base").getHost() == "www.example.org"]
// Your settings go here
[END]
# Match base path
[site("base").getPath() == "/"]
// Your settings go here
[END]
# Match root page uid
[site("rootPageId") == 1]
// Your settings go here
[END]
# Match a configuration property
[traverse(site("configuration"), "myCustomProperty") == true]
// Your settings go here
[END]