Conditions

Frontend TypoScript conditions offer a way to conditionally change TypoScript based on current context. Do not confuse conditions with the "if" function, which is a stdWrap property to act on current data.

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.

applicationContext

applicationContext
Data type

String

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

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
[applicationContext == "Development"]
    # ...
[END]

# Any context that is "Production" or starts with "Production"
# (for example, Production/Staging").
[applicationContext matches "/^Production/"]
    # ...
[END]
Copied!

page

page
Data type

Array

All data of the current page record as array.

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
# Check single page UID
[traverse(page, "uid") == 2]
    # ...
[END]

# Check list of page UIDs
[traverse(page, "uid") in [17,24]]
    # ...
[END]

# Check list of page UIDs NOT in
[traverse(page, "uid") not in [17,24]]
    # ...
[END]

# Check range of pages (example: page UID from 10 to 20)
[traverse(page, "uid") in 10..20]
    # ...
[END]

# Check the page backend layout
[traverse(page, "backend_layout") == 5]
    # ...
[END]
[traverse(page, "backend_layout") == "example_layout"]
    # ...
[END]

# Check the page title
[traverse(page, "title") == "foo"]
    # ...
[END]
Copied!

tree

tree
Data type

Object

Object with tree information.

tree.level

tree.level
Data type

Integer

The current tree level.

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
# Check, if the page is on level 0:
[tree.level == 0]
    # ...
[END]
Copied!

tree.pagelayout

tree.pagelayout
Data type

Integer / String

Check for the defined backend layout of a page, including the inheritance of the field Backend Layout (subpages of this page).

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
# Using backend layout records
[tree.pagelayout == 2]
    # ...
[END]

# Using the TSconfig provider of backend layouts
[tree.pagelayout == "pagets__Home"]
    # ...
[END]
Copied!

tree.rootLine

tree.rootLine
Data type

Array

Array of arrays with UID and PID.

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
[tree.rootLine[0]["uid"] == 1]
    # ...
[END]
Copied!

tree.rootLineIds

tree.rootLineIds
Data type

Array

An array with UIDs of the root line.

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
# Check, if page with uid 2 is inside the root line
[2 in tree.rootLineIds]
    # ...
[END]
Copied!

tree.rootLineParentIds

tree.rootLineParentIds
Data type

Array

An array with parent UIDs of the root line.

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
# Check, if the page with UID 2 is the parent of a page inside the root line
[2 in tree.rootLineParentIds]
    # ...
[END]
Copied!

backend

backend
Data type

Object

Object with backend information.

backend.user

backend.user
Data type

Object

Object with current backend user information.

backend.user.isAdmin

backend.user.isAdmin
Data type

Boolean

True, if the current backend user is administrator.

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
# Evaluates to true, if the current backend user is administrator
[backend.user.isAdmin]
    # ...
[END]
Copied!

backend.user.isLoggedIn

backend.user.isLoggedIn
Data type

Boolean

True, if the current backend user is logged in.

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
# Evaluates to true, if a backend user is logged in
[backend.user.isLoggedIn]
    # ...
[END]
Copied!

backend.user.userId

backend.user.userId
Data type

Integer

UID of the the current backend user.

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
# Evaluates to true, if the user UID of the current logged-in backend
# user is equal to 5
[backend.user.userId == 5]
    # ...
[END]
Copied!

backend.user.userGroupIds

backend.user.userGroupIds
Data type

Array

Context

Frontend, backend

Array of user group IDs assigned to the current backend user.

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
[2 in backend.user.userGroupIds]
    # ...
[END]
Copied!

backend.user.userGroupList

backend.user.userGroupList
Data type

String

Comma-separated list of group UIDs.

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
[like(","~backend.user.userGroupList~",", "*,1,*")]
    # ...
[END]
Copied!

frontend

frontend
Data type

Object

Object with frontend information.

frontend.user

frontend.user
Data type

Object

Object with current frontend user information.

frontend.user.isLoggedIn

frontend.user.isLoggedIn
Data type

Boolean

True, if the current frontend user is logged in.

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
[frontend.user.isLoggedIn]
    # ...
[END]
Copied!

frontend.user.userId

frontend.user.userId
Data type

Integer

The UID of the current frontend user.

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
[frontend.user.userId == 5]
    # ...
[END]
Copied!

frontend.user.userGroupIds

frontend.user.userGroupIds
Data type

Array

Context

Frontend

Array of user group IDs of the current frontend user.

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
[4 in frontend.user.userGroupIds]
    # ...
[END]
Copied!

frontend.user.userGroupList

frontend.user.userGroupList
Data type

String

Comma-separated list of group UIDs.

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
[like(","~frontend.user.userGroupList~",", "*,1,*")]
    # ...
[END]
Copied!

workspace

workspace
Data type

Object

Object with workspace information.

workspace.workspaceId

workspace.workspaceId
Data type

Integer

UID of the current workspace.

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
# Check, if in live workspace
[workspace.workspaceId == 0]
    # ...
[END]
Copied!

workspace.isLive

workspace.isLive
Data type

Boolean

True, if the current workspace is the live workspace.

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
[workspace.isLive]
    # ...
[END]
Copied!

workspace.isOffline

workspace.isOffline
Data type

Boolean

True, if the current workspace is offline.

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
[workspace.isOffline]
    # ...
[END]
Copied!

typo3

typo3
Data type

Object

Object with TYPO3-related information.

typo3.version

typo3.version
Data type

String

TYPO3_version (for example, 12.4.5)

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
[typo3.version == "12.4.5"]
    # ...
[END]
Copied!

typo3.branch

typo3.branch
Data type

String

TYPO3 branch (for example, 12.4)

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
[typo3.branch == "12.4"]
    # ...
[END]
Copied!

typo3.devIpMask

typo3.devIpMask
Data type

String

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

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
[typo3.devIpMask == "172.18.0.6"]
    # ...
[END]
Copied!

date()

date()
Parameter

String

Data type

String | Integer

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

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
# True, if the day of the current month is 7
[date("j") == 7]
    # ...
[END]

# True, if the day of the current week is 7
[date("w") == 7]
    # ...
[END]

# True, if the day of the current year is 7
[date("z") == 7]
    # ...
[END]

# True, if the current hour is 7
[date("G") == 7]
    # ...
[END]
Copied!

like()

like()
Parameter

String, String

Data type

Boolean

This function has two parameters: The first parameter is the string to search in, the second parameter is the search string.

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
# Search a string with * within another string
[like("fooBarBaz", "*Bar*")]
    # ...
[END]

# Search string with single characters in between, using ?
[like("fooBarBaz", "f?oBa?Baz")]
    # ...
[END]

# Search string using regular expression
[like("fooBarBaz", "/f[o]{2,2}[aBrz]+/")]
    # ...
[END]
Copied!

traverse()

traverse()
Parameter

Array, String

Data type

Mixed

This function gets a value from an array with arbitrary depth and suppresses a 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:

EXT:site_package/Configuration/TypoScript/setup.typoscript
# Traverse query parameters of current request along tx_news_pi1[news]
[request && traverse(request.getQueryParams(), 'tx_news_pi1/news') > 0]
Copied!

compatVersion()

compatVersion()
Parameter

String

Data type

Boolean

Compares against the current TYPO3 branch.

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
# True, if the current TYPO3 version is 12.4.x
[compatVersion("12.4")]
    # ...
[END]

# True, if the current TYPO3 version is 12.4.5
[compatVersion("12.4.5")]
    # ...
[END]
Copied!

loginUser()

Deprecated since version 12.4

This function has been marked as deprecated with TYPO3 v12 and should not be used anymore. Use the variables frontend.user and backend.user instead. See the changelog for more details.

Function
loginUser()
Parameter
String
Type
Boolean
Description
Value or constraint, wildcard or RegExp.
Migration
EXT:site_package/Configuration/TypoScript/setup.typoscript
# Before
[loginUser('*')]
  page = PAGE
  page.10 = TEXT
  page.10.value = User is logged in
[END]
# After
[frontend.user.isLoggedIn]
  page = PAGE
  page.11 = TEXT
  page.11.value = User is logged in
[END]

# Before
[loginUser(13)]
  page = PAGE
  page.20 = TEXT
  page.20.value = Frontend user has the uid 13
[END]
# After
[frontend.user.userId == 13]
  page = PAGE
  page.21 = TEXT
  page.21.value = Frontend user has the uid 13
[END]

# Before
[loginUser('1,13')]
  page = PAGE
  page.30 = TEXT
  page.30.value = Frontend user uid is 1 or 13
[END]
# After
[frontend.user.userId in [1,13]]
  page = PAGE
  page.31 = TEXT
  page.31.value = Frontend user uid is 1 or 13
[END]
Copied!

getTSFE()

getTSFE()
Data type

Object

Provides access to TypoScriptFrontendController $GLOBALS['TSFE']. This function can directly access methods of TypoScriptFrontendController. This class is target of a mid-term refactoring. It should be used with care since it will eventually vanish in the future.

Using the getTSFE() function, developers have to ensure that "TSFE" is available before accessing its properties. A missing "TSFE", for example, in backend context, does no longer automatically evaluate the whole condition to false. Instead, the function returns null, which can be checked using either [getTSFE() && getTSFE().id == 17] or the null-safe operator [getTSFE()?.id == 17].

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
# True, if the current page UID is 17. Use the page variable instead
[getTSFE()?.id == 17]
Copied!

getenv()

getenv()
Data type

String

PHP function getenv.

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
[getenv("VIRTUAL_HOST") == "www.example.org"]
    # ...
[END]
Copied!

feature()

feature()
Data type

String

Provides access to the current state of feature toggles.

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
# True, if the feature toggle for enforcing the Content Security Policy
# in the frontend is enabled
[feature("security.frontend.enforceContentSecurityPolicy") === true]
    # ...
[END]
Copied!

usergroup()

Deprecated since version 12.4

This function has been marked as deprecated with TYPO3 v12 and should not be used anymore. Use the variables frontend.user and backend.user instead. See the changelog for more details.

Function
usergroup()
Parameter
String
Value
Boolean
Description
Value or constraint, wildcard or RegExp. Allows to check whether current user is member of the expected usergroup.
Migration
EXT:site_package/Configuration/TypoScript/setup.typoscript
# Before
[usergroup('*')]
  page = PAGE
  page.10 = TEXT
  page.10.value = A frontend user is logged in and belongs to some user group.
[END]
# After
# Prefer [frontend.user.isLoggedIn] to not rely on magic array values.
[frontend.user.userGroupIds !== [0, -1]]
  page = PAGE
  page.11 = TEXT
  page.11.value = A frontend user is logged in and belongs to some user group.
[END]

# Before
[usergroup(11)]
  page = PAGE
  page.20 = TEXT
  page.20.value = Frontend user is member of group with uid 11
[END]
# After
[11 in frontend.user.userGroupIds]
  page = PAGE
  page.21 = TEXT
  page.21.value = Frontend user is member of group with uid 11
[END]

# Before
[usergroup('1,11')]
  page = PAGE
  page.30 = TEXT
  page.30.value = Frontend user is member of group 1 or 11
[END]
# After
[1 in frontend.user.userGroupIds || 11 in frontend.user.userGroupIds]
  page = PAGE
  page.31 = TEXT
  page.31.value = Frontend user is member of group 1 or 11
[END]
Copied!

ip()

Deprecated since version 12.3

Using this function in page TSconfig or user TSconfig conditions is deprecated. Such conditions will stop working with TYPO3 v13 and will then always evaluate to false. For migration hints see the changelog.

ip()
Parameter

String

Data type

Boolean

Value or constraint, wildcard or regular expression possible; special value: "devIP" (matches the devIPmask).

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
[ip("172.18.*")]
    page.10.value = Your IP matches "172.18.*"
[END]

[ip("devIP")]
    page.10.value = Your IP matches the configured devIp
[END]
Copied!

request()

Deprecated since version 12.3

Using this function in page TSconfig or user TSconfig conditions is deprecated. Such conditions will stop working with TYPO3 v13 and will then always evaluate to false. For migration hints see the changelog.

request()
Data type

Mixed

Allows to fetch information from current request.

request.getQueryParams()

request.getQueryParams()
Data type

Array

Allows to access GET parameters from current request.

Assuming the following query within URL:

route=%2Fajax%2Fsystem-information%2Frender&token=5c53e9b715362e7b0c3275848068133b89bbed77&skipSessionUpdate=1

then the following array would be provided:

Key: route
Value: /ajax/system-information/render
Key: token
Value: 5c53e9b715362e7b0c3275848068133b89bbed77
Key: skipSessionUpdate
Value: 1

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
# Safely check the query parameter array to avoid error logs in case key
# is not defined. This will check if the GET parameter
# tx_news_pi1[news] in the URL is greater than 0:
[request && traverse(request.getQueryParams(), 'tx_news_pi1/news') > 0]
    # ...
[END]
Copied!

request.getParsedBody()

request.getParsedBody()
Data type

Array

Provide all values contained in the request body, for example, in case of submitted form via POST, the submitted values.

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
[request && traverse(request.getParsedBody(), 'foo') == 1]
    # ...
[END]
Copied!

request.getHeaders()

request.getHeaders()
Data type

Array

Provide all values from request headers.

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
[request && request.getHeaders()['Accept'] == 'json']
    page.10.value = Accepts json
[END]

[request && request.getHeaders()['host'][0] == 'www.example.org']
    page.20.value = The host is www.example.org
[END]
Copied!

request.getCookieParams()

request.getCookieParams()
Data type

Array

Provides available cookies.

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
[request && request.getCookieParams()['foo'] == 1]
    # ...
[END]
Copied!

request.getNormalizedParams()

request.getNormalizedParams()
Data type

Array

Provides access to the \TYPO3\CMS\Core\Http\NormalizedParams object. Have a look at the normalized parameters of the request object for a list of the available methods.

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
[request && request.getNormalizedParams().isHttps()]
    page.10.value = HTTPS is being used
[END]

[request && request.getNormalizedParams().getHttpHost() == "example.org"]
    page.10.value = The host is "example.org"
[END]
Copied!

request.getPageArguments()

request.getPageArguments()
Data type

Object

Get the current \TYPO3\CMS\Core\Routing\PageArguments object with the resolved route parts from enhancers.

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
[request && request.getPageArguments().get('foo_id') > 0]
    # ...
[END]

# True, if current page type is 98
[request && request.getPageArguments()?.getPageType() == 98]
    # ...
[END]
Copied!

session()

session()
Parameter

String

Data type

Mixed

Allows to access values of the current session. Available values depend on values written to the session, for example, by extensions. Use | to dig deeper into the structure for stored values.

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
# Match, if the session has the value 1234567 in the structure :php:`$foo['bar']`:
[session("foo|bar") == 1234567]
    # ...
[END]
Copied!

site()

site()
Parameter

String

Data type

Mixed

Get a value from the site configuration, or null, if no site was found or the property does not exists.

Available information:

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

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
# Site identifier
[site("identifier") == "my_site"]
    # ...
[END]

# Match site base host
[site("base").getHost() == "www.example.org"]
    # ...
[END]

# Match base path
[site("base").getPath() == "/"]
    # ...
[END]

# Match root page UID
[site("rootPageId") == 1]
    # ...
[END]

# Match a configuration property
[traverse(site("configuration"), "myCustomProperty") == true]
    # ...
[END]
Copied!

siteLanguage()

siteLanguage()
Parameter

String

Data type

Mixed

Get a value from the site language configuration, or null if no site was found or property not exists.

Available information:

siteLanguage("languageId")
Returns the language ID as an integer.
siteLanguage("locale")
Returns the current locale as a string, for example en_GB or de_DE.
siteLanguage("base")
Returns the configured base URL as a string.
siteLanguage("title")
Returns the internal human-readable name for this language as a string.
siteLanguage("navigationTitle")
Returns the navigation title as a string.
siteLanguage("flagIdentifier")
Returns the flag identifier as a string, for example gb.
siteLanguage("typo3Language")
Returns the language identifier used in TYPO3 XLIFF files as a string, for example default or the two-letter language code.
siteLanguage("twoLetterIsoCode")

Deprecated since version 12.3

Returns the two-letter code for the language according to ISO-639 nomenclature as a string.

siteLanguage("hreflang")

Changed in version 12.4

This option is not relevant anymore for regular websites without rendering hreflang tag, but is now customizable, and has a proper fallback.

Returns the language information for the hreflang tag as a string.

siteLanguage("direction")

Deprecated since version 12.3

Returns the text direction for content in this language (left-to-right or right-to-left) as a string.

siteLanguage("fallbackType")
Returns the language fallback mode as a string, one of fallback, strict or free.
siteLanguage("fallbackLanguageIds")
Returns the list of fallback languages as a string, for example 1,0.

Example:

EXT:site_package/Configuration/TypoScript/setup.typoscript
[siteLanguage("locale") == "de_CH"]
    page.10.value = This site has the locale "de_CH"
[END]

[siteLanguage("title") == "Italy"]
    page.10.value = This site has the title "Italy"
[END]
Copied!