Conditions in Backend TypoScript / TSconfig 

TSconfig TypoScript conditions are a way to change TypoScript in response to the current context. See the TypoScript syntax condition chapter for basic syntax.

TypoScript conditions are available in both user TSconfig and page TSconfig but the variables and functions differ.

The Symfony expression language can throw warnings when sub arrays are checked in a condition that does not exist. Use the traverse function to avoid this.

Condition variables available in TSconfig 

applicationContext 

applicationContext

applicationContext
Type
string

The current application context as a string. See Application context.

Example: Condition applies in application context "Development" 

EXT:site_package/Configuration/page.tsconfig
[applicationContext == "Development"]
    // Your settings go here
[END]
Copied!

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"):

EXT:site_package/Configuration/page.tsconfig
[applicationContext matches "/^Production/"]
    // Your settings go here
[END]
Copied!

page 

page

page
Type
array

All data in the current page record as an array. Only available in page TSconfig, not in user TSconfig.

Example: Condition applies only on certain pages 

EXT:site_package/Configuration/page.tsconfig
# 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]
Copied!

tree 

tree

tree
Type
Object

Object with tree information. Only available in page TSconfig, not in user TSconfig.

tree.level 

tree.level

tree.level
Type
integer

The 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 

EXT:site_package/Configuration/page.tsconfig
# Check if page is on level 1 (root):
[tree.level == 1]
    // Your settings go here
[END]
Copied!

tree.pagelayout 

tree.pagelayout

tree.pagelayout
Type
integer / string

Check for the page backend layout including the inheritance in 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 

EXT:site_package/Configuration/page.tsconfig
# 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]
Copied!

tree.rootLine 

tree.rootLine

tree.rootLine
Type
array

An array of arrays with UIDs and PIDs. Only available in page TSconfig, not in user TSconfig.

Example: Condition applies on all subpages of page 

EXT:site_package/Configuration/page.tsconfig
[tree.rootLine[0]["uid"] == 1]
    // Your settings go here
[END]
Copied!

tree.rootLineIds 

tree.rootLineIds

tree.rootLineIds
Type
array

An array of 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 

EXT:site_package/Configuration/page.tsconfig
# Check if page with uid 2 is inside the root line
[2 in tree.rootLineIds]
    // Your settings go here
[END]
Copied!

tree.rootLineParentIds 

tree.rootLineParentIds

tree.rootLineParentIds
Type
array

An array of 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 

EXT:site_package/Configuration/page.tsconfig
# 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]
Copied!

backend 

backend

backend
Type
Object

Object with backend information.

backend.user 

backend.user

backend.user
Type
Object

Object with current backend user information.

backend.user.isAdmin 

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 

EXT:site_package/Configuration/page.tsconfig
# Evaluates to true if current backend user is administrator
[backend.user.isAdmin]
    // Your settings go here
[END]
Copied!

backend.user.isLoggedIn 

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 

EXT:site_package/Configuration/page.tsconfig
[backend.user.isLoggedIn]
    // Your settings go here
[END]
Copied!

backend.user.userId 

backend.user.userId

backend.user.userId
Type
integer

UID of current user.

Example: Condition applies if a certain backend user is logged in 

EXT:site_package/Configuration/page.tsconfig
# 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]
Copied!

backend.user.userGroupIds 

backend.user.userGroupList

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 

EXT:site_package/Configuration/page.tsconfig
[2 in backend.user.userGroupIds]
    // Your settings go here
[END]
Copied!

backend.user.userGroupList 

backend.user.userGroupList

backend.user.userGroupList
Type
string

Comma-separated list of group UIDs.

Example: Condition applies if the groups of a user meet a certain pattern 

EXT:site_package/Configuration/page.tsconfig
[like(","~backend.user.userGroupList~",", "*,1,*")]
    // Your settings go here
[END]
Copied!

workspace 

workspace

workspace
Type
Object

Object with workspace information

workspace.workspaceId 

.workspaceId

.workspaceId
Type
integer

UID of current workspace.

Example: Condition applies only in a certain workspace 

EXT:site_package/Configuration/page.tsconfig
[workspace.workspaceId == 0]
    // Your settings go here
[END]
Copied!

workspace.isLive 

workspace.isLive

workspace.isLive
Type
boolean

True if current workspace is live.

Example: Condition applies only in live workspace 

EXT:site_package/Configuration/page.tsconfig
[workspace.isLive]
    // Your settings go here
[END]
Copied!

workspace.isOffline 

workspace.isOffline

workspace.isOffline
Type
boolean

True if current workspace is offline

Example: Condition applies only in offline workspace 

EXT:site_package/Configuration/page.tsconfig
[workspace.isOffline]
    // Your settings go here
[END]
Copied!

typo3 

typo3

typo3
Type
Object

Object with TYPO3 related information

typo3.version 

typo3.version

typo3.version
Type
string

TYPO3 version (e.g. 13.4.0-dev)

Example: Condition only applies in an exact TYPO3 version like 13.4.0 

EXT:site_package/Configuration/page.tsconfig
[typo3.version == "13.4.0"]
    // Your settings go here
[END]
Copied!

typo3.branch 

typo3.branch

typo3.branch
Type
string

TYPO3 branch (e.g. 13.4)

Example: Condition applies in all TYPO3 versions of a branch like 13.4 

EXT:site_package/Configuration/page.tsconfig
[typo3.branch == "13.4"]
    // Your settings go here
[END]
Copied!

typo3.devIpMask 

typo3.devIpMask

typo3.devIpMask
Type
string

$GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask']

Example: Condition only applies if the devIpMask is set to a certain value 

EXT:site_package/Configuration/page.tsconfig
[typo3.devIpMask == "203.0.113.6"]
    // Your settings go here
[END]
Copied!

Condition functions available in TSconfig 

date() 

date([parameter])

date([parameter])
Type
integer
Parameter
[parameter]: string / integer

Get current date in given format. See PHP date function as a reference for possible usage.

Example: Condition applies at certain dates or times 

EXT:site_package/Configuration/page.tsconfig
# 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]
Copied!

like() 

like([search-string], [pattern])

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 

EXT:site_package/Configuration/page.tsconfig
# 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]
Copied!

traverse() 

traverse([array], [key])

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 warnings when subarrays do not exist. It has two parameters: the first parameter is the array to traverse, the second parameter is the path to traverse.

If the path is not found in the array, an empty string is returned.

Example: Condition applies if request parameter matches a certain value 

EXT:site_package/Configuration/page.tsconfig
# Traverse query parameters of current request along tx_news_pi1[news]
[traverse(request.getQueryParams(), 'tx_news_pi1/news') > 0]
    // Your settings go here
[END]
Copied!

compatVersion() 

compatVersion([version-pattern])

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 

EXT:site_package/Configuration/page.tsconfig
# True if current version is 13.4.x
[compatVersion("13.4")]
    // Your settings go here
[END]
[compatVersion("13.4.0")]
    // Your settings go here
[END]
[compatVersion("13.4.1")]
    // Your settings go here
[END]
Copied!

getenv() 

getenv([enviroment_variable])

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 

EXT:site_package/Configuration/page.tsconfig
[getenv("VIRTUAL_HOST") == "www.example.org"]
    // Your settings go here
[END]
Copied!

feature() 

feature([feature_key])

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 

EXT:site_package/Configuration/page.tsconfig
# True if feature toggle for strict TypoScript syntax is enabled:
[feature("TypoScript.strictSyntax") === false]
    // Your settings go here
[END]
Copied!

site() 

site([keyword])

site([keyword])
Type
string
Parameter
[keyword]: string

Get value from site configuration, or null if no site was found or property does not exist. Only available in page TSconfig, not available in user TSconfig. Available Information:

site("identifier")
Returns the identifier of current site as a string.
site("base")
Returns the base of current site as a string.
site("rootPageId")
Returns the root page uid of current site as an integer.
site("languages")
Returns an array of available languages for current site. For more information, see siteLanguage().
site("allLanguages")
Returns an array of available and unavailable languages for the current site. For more information, see siteLanguage().
site("defaultLanguage")
Returns the default language for current site. For more information, see siteLanguage().
site("configuration")
Returns an array with all available configuration for the current site.

Example: Condition applies if a certain value is set in the site configuration 

EXT:site_package/Configuration/page.tsconfig
# 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]
Copied!