Conditions¶
See also
- For full explanations about the condition syntax, please refer to the TypoScript Syntax chapter of the Core API. The “new” condition syntax (since TYPO3 9.4) is based on the symfony expression language
- TypoScript also offers the “if” function to create conditions.
Upgrading¶
The “old” condition syntax has been deprecated in 9 and will be removed in 10.
Hint
If it is not possible yet to fully migrate to Symfony expression language,
the feature toggle [SYS][features][TypoScript.strictSyntax]
can be disabled via
Settings -> Feature Toggles or directly in LocalConfiguration.php
or AdditionalConfiguration.php
.
Before updating from 9 to 10, you MUST change your templates to use the “new” condition syntax.
Look for notices in the deprecation log, such as:
Mon, 27 Jul 2020 15:58:06 +0200 [NOTICE] request="a4130429dafc6" component="TYPO3.CMS.deprecations":
Core: Error handler (BE): TYPO3 Deprecation Notice:
Multiple conditions blocks combined with AND, OR, && or || will be removed in TYPO3 v10.0, use
the new expression language. in ....
However, the deprecation log will only show you deprecations for pages that are being rendered. To get a full overview of old conditions, you should search through your own extensions and possibly the TypoScript templates in the database (available through the “Templates” backend module).
old:
# page uid == 2
[page|uid = 2]
# page layout == 1
[page|layout = 1]
# applicationContext is "Production"
[applicationContext = Production*]
new:
[page["uid"] == 2]
[page["layout"] == 1]
[applicationContext == "Production"]
Reference¶
Variables¶
The following variables are available. The values are context related.
applicationContext¶
- Variable
- applicationContext
- Type
- String
- Description
Current application context as string.
See Application Context.
- Beispiel
[applicationContext == "Development"]
page¶
- Variable
- page
- Type
- Array
- Description
- Current page record as array.
- Example
[page["uid"] == 2]
Constant¶
- Variable
- {$foo.bar}
- Type
- Constant
- Description
- Any TypoScript constant is available like before. Depending on the type of the constant you have to use different conditions.
- Example
If constant is an integer:
[{$foo.bar} == 4711]
If constant is a string put constant in quotes:
["{$foo.bar}" == "4711"]
tree¶
- Variable
- tree
- Type
- Object
- Description
- Object with tree information.
tree.level¶
- Variable
- tree.level
- Type
- Integer
- Description
- Current tree level.
- Example
Check whether page is on level 0:
[tree.level == 0]
tree.rootLine¶
- Variable
- tree.rootLine
- Type
- Array
- Description
- Array of arrays with uid and pid.
- Example
[tree.rootLine[0]["uid"] == 1]
tree.rootLineIds¶
- Variable
- tree.rootLineIds
- Type
- Array
- Description
- An array with UIDs of the rootline.
- Example
Check whether page with uid 2 is inside the root line:
[2 in tree.rootLineIds]
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.admin¶
- Variable
- backend.user.admin
- Type
- Boolean
- Description
- True if current user is admin
- Example
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
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
Evaluates to true if user uid of current logged in BE-User is equal to 5:
[backend.user.userId == 5]
backend.user.userGroupList¶
- Variable
- backend.user.userGroupList
- Type
- String
- Description
- Comma list of group UIDs
- Example
[like(","~backend.user.userGroupList~",", "*,1,*")]
frontend¶
- Variable
- frontend
- Type
- Object
- Description
- object with frontend information (available in FE only)
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
[frontend.user.isLoggedIn]
frontend.user.userId¶
- Variable
- .user.userId
- Type
- Integer
- Description
- UID of current user
- Example
[frontend.user.userId == 5]
frontend.user.userGroupList¶
- Variable
- frontend.user.userGroupList
- Type
- String
- Description
- Comma list of group UIDs
- Example
[like(","~frontend.user.userGroupList~",", "*,1,*")]
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
[typo3.version == "9.5.5"]
typo3.branch¶
- Variable
- typo3.branch
- Type
- String
- Description
- TYPO3_branch (e.g. 9.4)
- Example
[typo3.branch == "9.5"]
typo3.devIpMask¶
- Variable
- typo3.devIpMask
- Type
- String
- Description
$GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask']
- Example
[typo3.devIpMask == "172.18.0.6"]
Functions in frontend and backend context¶
Functions take over the logic of the old conditions which do more than a simple comparison check. The following functions are available in frontend and backend context, but not CLI:
request¶
- 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 all available 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
- Key:
- Example
Check if query parameter skipSessionUpdate equals 1:
[request.getQueryParams()['skipSessionUpdate'] == 1]
Safely check query parameter array to avoid error logs in case key is not defined (see condition-function-traverse). This will check if
tx_news_pi1['news'] > 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
[request.getParsedBody()['foo'] == 1]
request.getHeaders()¶
- Function
- request.getHeaders()
- Parameter
- Custom
- Type
- Array
- Description
- Provides all values from request headers.
- Example
[request.getHeaders()['Accept'] == 'json']
[request.getHeaders()['host'][0] == 'www.typo3lexikon.de']
request.getCookieParams()¶
- Function
- request.getCookieParams()
- Parameter
- Custom
- Type
- Array
- Description
- Provides all available cookies.
- Example
[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:
docs.typo3.org
isHttps()
- Returns boolean whether SSL was used.
getRequestHost()
- Example:
docs.typo3.org
getRequestHostOnly()
- Example:
docs.typo3.org
getRequestPort()
- Returns the port, mostly
80
or443
, but can be whatever is configured. getScriptName()
- Example:
/typo3/index.php
getRequestUri()
- Example:
/typo3/index.php?route=%2Fajax%2Fsystem-information%2Frender
getRequestUrl()
- Example:
https://typo3.org/typo3/index.php?route=%2Fajax%2Fsystem-information%2Frender
getRequestScript()
- Example:
https://typo3.org/typo3/index.php
getRequestDir()
- Example:
https://typo3.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:
typo3.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.
typo395.ddev.local/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
[request.getNormalizedParams().isHttps()]
[request.getNormalizedParams().getHttpHost() == "typo395.ddev.local"]
request.getPageArguments()¶
- Function
- request.getPageArguments()
- Parameter
- None
- Type
- Array
- Description
- Get current
PageArguments
object with resolved route parts from enhancers. - Example
[request.getPageArguments().get(‘foo_id’) > 0]
Allows migration from old condition syntax using
[globalVar = GP:singlepartner > 0]
to[request.getPageArguments().get('singlepartner') > 0]
.
Functions in all contexts¶
The following functions are available in any context:
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
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
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]+/")]
ip¶
- Function
- ip
- Parameter
- String
- Type
- Boolean
- Description
- Value or Constraint, Wildcard or RegExp possible special value: devIP (match the devIPMask).
- Example
Check whether IP matches:
[ip("172.18.*")]
Check whether IP matches configured devIp:
[ip("devIP")]
compatVersion¶
- Function
- compatVersion
- Parameter
- String
- Type
- Boolean
- Description
- Compares against the current TYPO3 branch.
- Example
[compatVersion("9.5")]
Is same as:
[compatVersion("9.5.0")]
Another example:
[compatVersion("9.5.1")]
loginUser¶
- Function
- loginUser
- Parameter
- String
- Type
- Boolean
- Description
value or constraint, wildcard or RegExp possible
Context dependent, uses BE-User within TSconfig, and FE-User within TypoScript.
- Example
Any logged in user:
[loginUser('*')]
User with uid 1:
[loginUser(1)]
User 1, 3 or 5:
[loginUser('1,3,5')]
Not logged in:
[loginUser('*') == false]
getTSFE¶
- Function
- getTSFE
- Parameter
- Object
- Description
- Provides access to TypoScriptFrontendController (
$GLOBALS['TSFE']
) - Example
Current typeNum:
[getTSFE().type == 98]
getenv¶
- Function
- getenv
- Parameter
- String
- Description
- PHP function: getenv
- Example
[getenv("VIRTUAL_HOST") == "docs.typo3.org"]
feature¶
- Function
- feature
- Parameter
- String
- Description
- Provides access to feature toggles current state.
- Example
Check if feature toggle for strict TypoScript syntax is enabled:
[feature("TypoScript.strictSyntax") === false]
usergroup¶
- Function
- usergroup
- Parameter
- String
- Value
- Boolean
- Description
Value or constraint, wildcard or RegExp possible
Allows to check whether current user (FE or BE) is part of the expected usergroup.
- Example
Any usergroup:
[usergroup("*")]
Usergroup 12:
[usergroup("12")]
Usergroup 12, 15 or 18:
[usergroup("12,15,18")]
Functions in frontend context¶
The following functions are only available in frontend context:
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
|
to dig deeper into the structure for stored values.- Example
Example, matches if session has value 1234567 in structure
$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
Site identifier:
[site("identifier") == "typo395"]
Matches if site base host:
[site("base").getHost() == "docs.typo3.org"]
Base path:
[site("base").getPath() == "/"]
Rootpage uid:
[site("rootPageId") == 1]
Configuration property:
[site("configuration")["enabled"] == 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")
siteLanguage("twoLetterIsoCode")
siteLanguage("hreflang")
siteLanguage("direction")
siteLanguage("fallbackType")
siteLanguage("fallbackLanguageIds")
- Example
Example, match if siteLanguage locale = foo:
[siteLanguage("locale") == "de_CH"]
Example, match if siteLanguage title = Italy:
[siteLanguage("title") == "Italy"]