Conditions

Frontend 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. 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

Variable

applicationContext

Type

String

Description

Current application context as string. See Application context.

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

# Any context that is "Production" or starts with "Production" (eg Production/Staging").
[applicationContext matches "/^Production/"]

page

Variable

page

Type

Array

Description

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]
# Check list of page uids
[traverse(page, "uid") in [17,24]]
# Check list of page uids NOT in
[traverse(page, "uid") not in [17,24]]
# Check range of pages (example: page uid from 10 to 20)
[traverse(page, "uid") in 10..20]

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

# Check the page title
[traverse(page, "title") == "foo"]

tree

Variable

tree

Type

Object

Description

Object with tree information.

tree.level

Variable

tree.level

Type

Integer

Description

Current tree level.

Example
EXT:site_package/Configuration/TypoScript/setup.typoscript
# Check if page is on level 0:
[tree.level == 0]

tree.pagelayout

Variable

tree.pagelayout

Type

Integer / String

Description

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]

# Using TSconfig provider of backend layouts
[tree.pagelayout == "pagets__Home"]

tree.rootLine

Variable

tree.rootLine

Type

Array

Description

Array of arrays with uid and pid.

Example
EXT:site_package/Configuration/TypoScript/setup.typoscript
[tree.rootLine[0]["uid"] == 1]

tree.rootLineIds

Variable

tree.rootLineIds

Type

Array

Description

An array with UIDs of the rootline.

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

tree.rootLineParentIds

Variable

tree.rootLineParentIds

Type

Array

Description

An array with parent UIDs of the root line.

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

backend

Variable

backend

Type

Object

Description

Object with backend information.

backend.user

Variable

backend.user

Type

Object

Description

Object with current backend user information.

backend.user.isAdmin

Variable

backend.user.isAdmin

Type

Boolean

Description

True if current user is admin.

Example
EXT:site_package/Configuration/TypoScript/setup.typoscript
# Evaluates to true if current BE-User is administrator
[backend.user.isAdmin]

backend.user.isLoggedIn

Variable

backend.user.isLoggedIn

Type

Boolean

Description

True if current user is logged in.

Example
EXT:site_package/Configuration/TypoScript/setup.typoscript
# Evaluates to true if an BE-User is logged in
[backend.user.isLoggedIn]

backend.user.userId

Variable

backend.user.userId

Type

Integer

Description

UID of current user.

Example
EXT:site_package/Configuration/TypoScript/setup.typoscript
# Evaluates to true if user uid of current logged in BE-User is equal to 5
[backend.user.userId == 5]

backend.user.userGroupIds

Variable

backend.user.userGroupList

Type

array

Description

Array of user group ids of the current backend user.

Context

Frontend, Backend

Example
EXT:site_package/Configuration/TypoScript/setup.typoscript
[2 in backend.user.userGroupIds]

backend.user.userGroupList

Variable

backend.user.userGroupList

Type

String

Description

Comma list of group UIDs

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

frontend

Variable

frontend

Type

Object

Description

Object with frontend information.

frontend.user

Variable

frontend.user

Type

Object

Description

Object with current frontend user information.

frontend.user.isLoggedIn

Variable

frontend.user.isLoggedIn

Type

Boolean

Description

True if current user is logged in.

Example
EXT:site_package/Configuration/TypoScript/setup.typoscript
[frontend.user.isLoggedIn]

frontend.user.userId

Variable

.user.userId

Type

Integer

Description

UID of current user.

Example
EXT:site_package/Configuration/TypoScript/setup.typoscript
[frontend.user.userId == 5]

frontend.user.userGroupIds

Variable

frontend.user.userGroupList

Type

array

Description

Array of user group ids of the current frontend user.

Context

Frontend

Example
EXT:site_package/Configuration/TypoScript/setup.typoscript
[4 in frontend.user.userGroupIds]

frontend.user.userGroupList

Variable

frontend.user.userGroupList

Type

String

Description

Comma list of group UIDs.

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

workspace

Variable

workspace

Type

Object

Description

object with workspace information

workspace.workspaceId

Variable

.workspaceId

Type

Integer

Description

UID of current workspace.

Example
EXT:site_package/Configuration/TypoScript/setup.typoscript
[workspace.workspaceId == 0]

workspace.isLive

Variable

workspace.isLive

Type

Boolean

Description

True if current workspace is live.

Example
EXT:site_package/Configuration/TypoScript/setup.typoscript
[workspace.isLive]

workspace.isOffline

Variable

workspace.isOffline

Type

Boolean

Description

True if current workspace is offline

Example
EXT:site_package/Configuration/TypoScript/setup.typoscript
[workspace.isOffline]

typo3

Variable

typo3

Type

Object

Description

Object with TYPO3 related information

typo3.version

Variable

typo3.version

Type

String

Description

TYPO3_version (e.g. 9.4.0-dev)

Example
EXT:site_package/Configuration/TypoScript/setup.typoscript
[typo3.version == "9.5.5"]

typo3.branch

Variable

typo3.branch

Type

String

Description

TYPO3_branch (e.g. 9.4)

Example
EXT:site_package/Configuration/TypoScript/setup.typoscript
[typo3.branch == "11.5"]

typo3.devIpMask

Variable

typo3.devIpMask

Type

String

Description

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

Example
EXT:site_package/Configuration/TypoScript/setup.typoscript
[typo3.devIpMask == "172.18.0.6"]

date()

Function

date()

Parameter

String

Type

String / Integer

Description

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

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

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

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

# True if current hour is 7
[date("G") == 7]

like()

Function

like()

Parameter

String, String

Type

Boolean

Description

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*")]

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

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

traverse()

Function

traverse()

Parameter

Array, String

Type

Custom

Description

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
EXT:site_package/Configuration/TypoScript/setup.typoscript
# Traverse query parameters of current request along tx_news_pi1[news]
[traverse(request.getQueryParams(), 'tx_news_pi1/news') > 0]

compatVersion()

Function

compatVersion()

Parameter

String

Type

Boolean

Description

Compares against the current TYPO3 branch.

Example
EXT:site_package/Configuration/TypoScript/setup.typoscript
# True if current version is 11.5.x
[compatVersion("11.5")]
[compatVersion("11.5.0")]
[compatVersion("11.5.1")]

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]

getTSFE()

Function

getTSFE()

Parameter

Object

Description

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 current page uid is 17. Use the page variable instead
[getTSFE()?.id == 17]

getenv()

Function

getenv()

Parameter

String

Description

PHP function getenv.

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

feature()

Function

feature()

Parameter

String

Description

Provides access to feature toggles current state.

Example
EXT:site_package/Configuration/TypoScript/setup.typoscript
# True if feature toggle for strict TypoScript syntax is enabled:
[feature("TypoScript.strictSyntax") === false]

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]

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.

Function

ip()

Parameter

String

Type

Boolean

Description

Value or Constraint, Wildcard or RegExp possible special value: devIP (match 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]

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.

Function

request()

Parameter

Custom

Description

Allows to fetch information from current request.

request.getQueryParams()

Function

request.getQueryParams()

Parameter

Custom

Type

Array

Description

Allows to access GET parameters from current request.

Assuming the following query within url:

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

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:
[traverse(request.getQueryParams(), 'tx_news_pi1/news') > 0]

request.getParsedBody()

Function

request.getParsedBody()

Parameter

Custom

Type

Array

Description

Provides all values contained in the request body, e.g. in case of submitted form via POST, the submitted values.

Example
EXT:site_package/Configuration/TypoScript/setup.typoscript
[request.getParsedBody()['foo'] == 1]

request.getHeaders()

Function

request.getHeaders()

Parameter

Custom

Type

Array

Description

Provides all values from request headers.

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

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

request.getCookieParams()

Function

request.getCookieParams()

Parameter

Custom

Type

Array

Description

Provides available cookies.

Example
EXT:site_package/Configuration/TypoScript/setup.typoscript
[request.getCookieParams()['foo'] == 1]

request.getNormalizedParams()

Function

request.getNormalizedParams()

Parameter

Custom

Type

Array

Description
Provides access to NormalizedParams object which contains a bunch of methods:
getHttpHost()

Example: www.example.org

isHttps()

Returns boolean whether SSL was used.

getRequestHost()

Example: www.example.org

getRequestHostOnly()

Example: www.example.org

getRequestPort()

Returns the port, mostly 80 or 443, but can be whatever is configured.

getScriptName()

Example: /typo3/index.php

getRequestUri()

Example: /typo3/index.php?route=%2Fajax%2Fsystem-information%2Frender

getRequestUrl()

Example: https://example.org/typo3/index.php?route=%2Fajax%2Fsystem-information%2Frender

getRequestScript()

Example: https://example.org/typo3/index.php

getRequestDir()

Example: https://example.org/typo3/

isBehindReverseProxy()

Returns boolean.

getRemoteAddress()

IP Adress of client, in case of docker this could be 172.18.0.6.

getScriptFileName()

Example: /var/www/html/public/typo3/index.php

getDocumentRoot()

Example: /var/www/html/public

getSiteUrl()

Example: example.org

getSitePath()

Example: /

getSiteScript()

Example: typo3/index.php?route=%2Fajax%2Fsystem-information%2Frender

getPathInfo()

Ist bei mir leer gewesen

getHttpReferer()

If enabled, delivers the prior visited url, e.g. example.org/typo3/index.php

getHttpUserAgent()

Example: Mozilla/5.0 (X11; Linux x86_64) Chrome/73.0.3683.86 Safari/537.36

getHttpAcceptEncoding()

Example: gzip, deflate

getHttpAcceptLanguage()

Example: de-DE,de;q=0.9

getRemoteHost()

Name of client pc.

getQueryString()

Example: route=%2Fajax%2Fsystem-information%2Frender

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

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

request.getPageArguments()

Function

request.getPageArguments()

Parameter

None

Type

Array

Description

Get current PageArguments object with resolved route parts from enhancers.

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

# True if current typenum is 98
[request.getPageArguments()?.getPageType() == 98]

session()

Function

session()

Parameter

String

Value

Mixed

Description

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

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

site()

Function

site

Parameter

String

Description

Get value from site configuration, or null if no site was found or property does not exists. 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
EXT:site_package/Configuration/TypoScript/setup.typoscript
# Site identifier
[site("identifier") == "typo395"]

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

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

# Match root page uid
[site("rootPageId") == 1]

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

siteLanguage()

Function

siteLanguage()

Parameter

String

Value

Mixed

Description

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

Available information:

  • siteLanguage("languageId")

  • siteLanguage("locale")

  • siteLanguage("base")

  • siteLanguage("title")

  • siteLanguage("navigationTitle")

  • siteLanguage("flagIdentifier")

  • siteLanguage("typo3Language") : default or 2 letter language code

  • siteLanguage("twoLetterIsoCode") : 2 letter language code

  • siteLanguage("hreflang")

  • siteLanguage("direction")

  • siteLanguage("fallbackType")

  • siteLanguage("fallbackLanguageIds")

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]