Data / getText
The get
data type is a kind of tool box for retrieving
values from different sources, for example, GET
/POST
variables,
registers, values from the page tree, items in the page menus and records
from database tables.
The general syntax is as follows:
lib.foo.data = <key> : <code>
where
<key>
indicates the source and
<code>
contains paths or
pointers to values. Possible keys and codes are described below.
The
code
can contain pipe characters
|
which will
result in a multidimensional array. This, for example, works with
TSFE
:
lib.foo.data = TSFE : fe_user | user | username
Some codes use a different separator, but this is documented in the
code.
Spaces around the colon (
:
) are irrelevant. The
key
is
case-insensitive.
Using multiple codes separated by a
//
(double slash) will return
the first one that is not empty ("" or zero). The TypoScript below gets the
content of the "header" field. If "header" is empty, "title" is
retrieved. If "title" is also empty, the "uid" field is retrieved:
lib.foo.data = field : header // field : title // field : uid
Properties
applicationcontext
New in version 13.0
applicationcontext
-
Returns the current application context as a string.
Example: Evaluate the current application context
Evaluate if the current application context is "Production":
if {
value.data = applicationcontext
equals = Production
}
asset
asset
-
New in version 13.2
Local resources can be cache-busted. It is no longer necessary to rename the asset when it is exchanged, forcing browsers to reload the file.
The getText
asset
function includes assets like images, CSS or JavaScript that are cache-busted.Depending on $GLOBALS['TYPO3_CONF_VARS']['FE']['versionNumberInFilename'] the cache buster is applied as a query string or embedded in the filename.
The result is the same as using the argument
use
in Uri.resource ViewHelper <f:uri.resource>.Cache Busting="true"
Example: Display extension icon with cache buster
page.20 = TEXT
page.20 {
value.stdWrap.data = asset: EXT:core/Resources/Public/Icons/Extension.svg
}
cObj
cObj
Example: Get the number of the current cObject record
lib.foo.data = cObj : parentRecordNumber
context
context
-
Access values from context API (see). If a property is an array, it is converted into a comma-separated list.
Syntax:
TypoScript Syntaxlib.foo.data = context:<aspectName>:<propertyName>
Copied!
Example: Retrieve current workspace ID
page.10 = TEXT
page.10.data = context:workspace:id
page.10.wrap = You are in workspace: |
current
current
-
Current (gets the "current" value)
Example: Get the current value
lib.foo.data = current
date
date
-
- Default
d/
m Y
Can be used with a colon and date-conf.
Example: Get the current time formatted dd-mm-yy
lib.foo.data = date : d-m-y
DB
DB
-
- Syntax
- DB : [table name] : [uid] : [field]
Value from the database. Any record from any table that is in the TCA can be selected here. Records marked as deleted will not return a value.
In contrast to the other keys, colons are used here instead of pipes to drill down into the structure.
Example: Get a header field value of a record
Get the value of the header field of record with uid 234 from table
tt_
:
lib.foo.data = DB : tt_content:234:header
Get the value of the header field of a record, where the uid is in the
my
GET parameter :
lib.foo.data.dataWrap = DB : tt_content:{GP : myContentId}:header
Note
It is safe to use client-/user-provided input for the id of a DB
record here. The function
Content
internally
calls the function
Page
, which converts the
parameter to an int via
Query
debug
debug
-
Returns HTML-formatted content of a PHP variable. Available variables are
root
,Line full
,Root Line data
,register
andpage
.
Example: Debug the current root-line
Outputs the current root-line visually in HTML:
lib.foo.data = debug : rootLine
field
field
-
- Syntax
- field : [a field name in the current
$c
array in the cObject, multidimensional]Obj->data
This gives read access to the value of an internal global variable depending on the key.
- By default, the
$c
array is the record of the current page.Obj->data - In TMENU
$c
is set to the page-record of each menu item in loop iterations during the rendering process.Obj->data - In CONTENT / RECORDS
$c
is set to the current recordObj->data - In GIFBUILDER
$c
is set to the data GIFBUILDER is supplied with.Obj->data
Example: Get header data
Get content from
$c
:
lib.foo.data = field : header
Example: Get data in a field
Get content from
$c
:
lib.foo.data = field : fieldname | level1 | level2
file
file
-
- Syntax
- file : [uid] : [property]
Retrieves a property from a file object (FAL) by identifying it through its
sys_
UID. Note that during execution of the FILES cObject, it is possible to reference the current file using current as the UID, for example,file file : current : size
.The following properties are available: name, uid, originalUid, size, sha1, extension, mimetype, contents, publicUrl, modification_date and creation_date.
Furthermore, when manipulating references (such as images in content elements and media on pages), these additional properties are available (not all are available all the time, it depends on the setup of references of the FILES cObject): title, description, link and alternative.
Any data in the
sys_
table can also be accessed.file_ metadata See the FILES cObject for examples of usage.
Example: Get the size of a file
Get the size of the file with sys_file UID 17:
lib.foo.data = file : 17 : size
flexform
flexform
-
- Syntax
- flexform : [field containing flexform data] : [property of this flexform]
Access values in FlexForms, for example, inside a
tt_
record.content
Example: Get a FlexForm value
Return the FlexForm value of given name:
lib.foo.data = flexform : pi_flexform:settings.categories
fullRootLine
fullRootLine
-
- Syntax
- fullRootLine : [pointer, integer], [field name], ["slide"]
Used to retrieve values from "above" the current page's
root. Assume that you are on the page "You are here!" in the page tree below.
Using the levelfield property, you
can only go up to the page "Site root", because it is the root of a new
(sub-)site.
full
allows you to go all the way up to the page
tree root. The numbers in square brackets indicate which page each
value of pointer would point to:
- Page tree root [-2]
|- 1. page before [-1]
|- Site root (root template here!) [0]
|- You are here! [1]
A "slide" parameter can be added (like in levelfield property).
Example: Get the title of the previous page
Get the title of the page before the start of the current website:
lib.foo.data = fullRootLine : -1, title
getenv
getenv
-
Value from PHP environment variables.
For a cached version of this feature, see getEnv.
Example: Get the HTTP referer
Get the environment variable HTTP_
.
lib.foo.data = getenv : HTTP_REFERER
getIndpEnv
getIndpEnv
-
- Syntax
- getIndpEnv : <name>
Returns the value of a System Environment Variable denoted by name regardless of server OS, CGI/MODULE version, etc. The result is usually identical to the
$_
variable. This method is more reliable then getEnv. Internal processing is handled bySERVER TYPO3\
CMS\ Core\ Utility\ General Utility:: get Indp Env () Available names:
Name Definition Example or result _ARRAY Return an array with all available key-value pairs for debugging purposes HTTP_ACCEPT_LANGUAGE language(s) accepted by client HTTP_HOST [host][:[port]] example.
org: 8080 HTTP_REFERER [scheme]://[host][:[port]][path] https://
example. org: 8080/ typo3/ 32/ temp/ phpcheck/ index. php/ arg1/ arg2/ arg3/?arg1,arg2,arg3&p1=parameter1&p2 [key]=value HTTP_USER_AGENT client user agent PATH_INFO [path_info] /arg1/
arg2/ arg3/ QUERY_STRING [query] arg1,arg2,arg3&p1=parameter1&p2
[key]=value REMOTE_ADDR client IP REMOTE_HOST client host REQUEST_URI [path]?[query] /typo3/
32/ temp/ phpcheck/ index. php/ arg1/ arg2/ arg3/?arg1,arg2,arg3&p1=parameter1&p2 [key]=value SCRIPT_FILENAME absolute filename of script SCRIPT_NAME [path_script] /typo3/
32/ temp/ phpcheck/ [index. php] TYPO3_DOCUMENT_ROOT absolute path of root of documents TYPO3_HOST_ONLY [host] example.
org TYPO3_PORT [port] 8080
TYPO3_REQUEST_DIR [scheme]://[host][:[port]][path_dir] TYPO3_REQUEST_HOST [scheme]://[host][:[port]] TYPO3_REQUEST_SCRIPT [scheme]://[host][:[port]][path_script] TYPO3_REQUEST_URL [scheme]://[host][:[port]][path]?[query] TYPO3_REV_PROXY TRUE if this session runs over a well known proxy TYPO3_SITE_SCRIPT [script / Speaking URL] of the TYPO3 website TYPO3_SITE_URL [scheme]://[host][:[port]][path_dir] of the TYPO3 website frontend TYPO3_SSL TRUE if this session uses SSL/TLS (https)
Example: Get the remote address
# get and output the client IP
page = PAGE
page.10 = TEXT
page.10.stdWrap.data = getIndpEnv : REMOTE_ADDR
page.10.stdWrap.htmlSpecialChars = 1
global
global
-
- Syntax
- global : [variable]
GP
GP
-
- Syntax
- GP : [Value from GET or POST method]
Get a variable from
$_
orGET $_
when a variable, which exists in both arrays, is returned fromPOST $_
.POST
Example: Get the input value from query string
Get input value from query string &stuff=...
lib.foo.data = GP : stuff
Get input value from query string &stuff
lib.foo.data = GP : stuff | bar
level
level
-
Get the root line level of the current page.
Example: Get the root line level of the current page
lib.foo.data = level
levelfield
levelfield
-
- Syntax
- levelfield : [pointer, integer], [field name], ["slide"]
Like leveltitle but you can choose which field should be fetched from the record.
Example: Get a field from a page up the root-line
Get the value of user-defined field
tx_
in the root line.
lib.foo.data = levelfield : -1, tx_myextension_myfield, slide
Changed in version 13.2
Until TYPO3 v13 it was required to do additional configuration in $GLOBALS['TYPO3_CONF_VARS']['FE']['addRootLineFields'] to use custom fields.
To stay compatible with both TYPO3 v12 and v13, add the following to your
extension's ext_
:
<?php
declare(strict_types=1);
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Utility\GeneralUtility;
defined('TYPO3') or die();
$versionInformation = GeneralUtility::makeInstance(Typo3Version::class);
// TODO: Remove when dropping TYPO3 v12 support
if ($versionInformation->getMajorVersion() < 13) {
$GLOBALS['TYPO3_CONF_VARS']['FE']['addRootLineFields'] .= ',tx_myextension_myfield';
}
levelmedia
levelmedia
-
- Syntax
- levelmedia : [pointer, integer], ["slide"]
Get the media field of a page in the root-line.
- Use an absolute level: 0 or a positive integer.
- Negative integers determine x levels up.
- The slide parameter slides until there is a non-empty value.
leveltitle
leveltitle
-
- Syntax
- leveltitle : [pointer, integer], ["slide"]
Get the title of a page in the root-line.
- Use an absolute level: 0 or a positive integer.
- Negative integers determine x levels up
- The slide parameter slides until there is a non-empty value.
Example: Get the title of a page up the root line
Get the title of the page on the first level of the root line:
lib.foo.data = leveltitle : 1
Get the title of the page on the level immediately below the current. If it is empty, walk to the bottom of the root line until there is a title:
lib.foo.data = leveltitle : -2, slide
leveluid
leveluid
-
- Syntax
- leveluid : [pointer, integer]
Get the UID of a page in the root line.
- Use an absolute level: 0 or a positive integer.
- Negative integers determine x levels up.
Example: Get the ID of the root page of the page tree
Get the ID of the root page of the website (level zero):
lib.foo.data = leveluid : 0
LLL
LLL
-
- Syntax
- LLL: [fileref]:[labelkey]
Reference to a locallang label (XLIFF). Reference consists of [fileref]:[labelkey]
Example: Get a localized label
Get the localized label for the logout button:
lib.foo.data = LLL : EXT:felogin/Resources/Private/Language/locallang.xlf:logout
page
page
-
- Syntax
- page: [field in the current page record]
Get the specified field from the current page
Example: Get the current page title
lib.foo.data = page : title
pagelayout
pagelayout
-
Get the current backend layout.
Example: Get the current backend layout
lib.foo.data = pagelayout
parameters
parameters
-
- Syntax
- parameters: [field name from the current
$c
array in the cObject.]Obj->parameters
Get the content of a key in the
parameters
array of the current cObject.
Example: Get the parameter color
Get content from
$c
:
lib.foo.data = parameters : color
path
path
-
Path to a file, for example, that is in an extension. Returns an empty value if the file does not exist.
Example: Resolve the path to a file
Get path to file rsaauth.
(inside extension rsaauth) relative to siteroot:
lib.foo.data = path : EXT:rsaauth/resources/rsaauth.js
It can also be helpful in combination with the stdWrap function :
page.headerData.10 = TEXT
page.headerData.10 {
data = path : EXT:site/Resources/Public/Images/logo.png
wrap = <a href="|">
}
register
register
-
- Syntax
- register: [field name from the
$GLOBALS
]['TSFE']->register
See LOAD_REGISTER.
Example: Get the content of a register
Get content from a register:
lib.foo.data = register : color
request
request
-
- Syntax
- request : [attribute] | [property] ( | [subproperty] | ... )
Retrieve the property of a PSR-7 request attribute.
Only scalar properties can be retrieved: int, float, string or bool values. If the property is an object or an array, a subproperty can be used to call the getter method of the object or retrieve the key of the array.
Example: Get the page type
lib.foo.data = request : routing | pageType
Example: Get a query argument
# Retrieve the value of the query parameter ?myParam=<value>
lib.foo.data = request : routing | queryArguments | myParam
# Retrieve the value of the query parameter ?tx_myext[key]=<value>
lib.foo.data = request : routing | queryArguments | tx_myext | key
Example: Get the nonce
lib.foo.data = request : nonce | value
session
session
-
- Syntax
- session : [key]
The
key
is the session key used to store a value.
Example: Get a value stored in the current session
Get the number of items of a stored shopping cart array/object:
lib.foo.data = session : shop_cart | itemCount
site
site
-
- Syntax
- site : [key]
Accesses the current site configuration.
Possible keys:attributes
- Additional parameters configured for this site.
base
- The base URL for this site.
base
Variants - The base variants of this site.
root
Page Id - The root page ID of this site.
identifier
- The identifier (name) of this site configuration.
website
Title - The website title of this site.
Example: Get values from the current site
page.10 = TEXT
page.10.data = site:base
page.10.wrap = This is your base URL: |
site
is the keyword, and the parts after the colon are the
configuration key(s) to access.
page.10 = TEXT
page.10.data = site:customConfigKey.nested.value
siteLanguage
siteLanguage
-
- Syntax
- siteLanguage : [key]
Accesses the current site language configuration.
Possible keys:attributes
- Additional parameters configured for this site language.
base
- The base URL for this language.
flag
Identifier -
The flag key (for example,
gb
orfr
) used in the TYPO3 backend.flag
can be used to match the site configuration setting. hreflang
-
The language tag for this language defined by RFC 1766 / 3066
hreflang
attributes.This option is not relevant for regular websites without rendering hreflang tag.
language
Id - The language mapped to the ID of the site language.
locale
Changed in version 12.3
The
locale
property in typoscript can be subdivided using subkeys separated by a colon:
. The subkeyslanguage
,Code country
, andCode full
allow access to the individual components of thelocale
value. For instance, alocale
value of "en_US.UTF-8" can be broken down into "en", "US", and for thefull
subkey, "en-US".language
: this contains the two-letter language code (previouslyCode site
)Language: two Letter Iso Code country
: contains the uppercase country code part of the localeCode full
: contains the entire locale (this is also the default if no subkey is specified)
The
locale
property represents the language, country, and character encoding settings for TYPO3. It is a composite value, such as "en_US.UTF-8", which can be dissected into different components via subkeys for more precise language and location specifications.navigation
Title - The label used in language menus.
title
- The label used in TYPO3 to identify the language.
typo3Language
- The prefix for TYPO3's language files (
default
for English), otherwise one of TYPO3's internal language keys. Previously configured via TypoScriptconfig.
.language = fr website
Title - The website title for this language. Note: there is no automatic fallback to the
site:
.website Title
Example: Get values from the current site language
page.10 = TEXT
page.10.data = siteLanguage:navigationTitle
page.10.wrap = This is the title of the current site language: |
page.20 = TEXT
page.20.dataWrap = The current site language's locale is {siteLanguage:locale}
# Website title for the current language with fallback
# to the website title of the site configuration.
page.30 = TEXT
page.30.data = siteLanguage:websiteTitle // site:websiteTitle
siteSettings
siteSettings
-
Access the site settings of the current site.
Example: Access the redirects HTTP status code
page.10 = TEXT
page.10.data = siteSettings:redirects.httpStatusCode
TSFE
TSFE
-
- Syntax
- TSFE: [value from the
$GLOBALS
array, multi-dimensional]['TSFE']
Returns a value from
\TYPO3\
.CMS\ Frontend\ Controller\ Typo Script Frontend Controller
Changed in version 13.0
The following TypoScriptFrontendController (TSFE) properties have been removed:
spam
Protect Email Addresses int
Target ext
Target file
Target base
Url
Migrate these properties to the config property. You can access the
TypoScript properties directly, for example, via
lib.
Example: Get the username field of the current frontend user
lib.foo.data = TSFE : fe_user | user | username