Data / getText

Data type:

getText

Description:

The getText data type is some kind of tool box allowing to retrieve values from a variety of sources, e.g. from GET/POST variables, from registers, values from the page tree, items in the page menus, records from any database table, etc.

The general syntax is as follows:

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = <key> : <code>

where <key> indicates the source and <code> is some form of path or pointer to the value, which depends on the key used. The various keys and their possible codes are described below.

The code can contain pipe characters | to separate keys in a multidimensional array. This e.g. works with TSFE:

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = TSFE : fe_user|user|username

Some codes work with a different separator, which is documented right at the code. Spaces around the colon (:) are irrelevant. The key is case-insensitive.

By separating the value of getText with // (double slash) a number of codes can be supplied and getText will return the first one, which is not empty ("" or zero).

To get the content of the field "header". If "header is empty, "title" is retrieved. If "title" is empty as well, it finally gets the field "uid":

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = field : header // field : title // field : uid

cObj

getText Key:

cObj

Description:

For CONTENT and RECORDS cObjects that are returned by a select query, this returns the row number (1,2,3,...) of the current cObject record.

parentRecordNumber is the only key available.

Example:

Get the number of the current cObject record:

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = cObj : parentRecordNumber

context

getText Key:

context

Description:

access values from context API (see). If a property is an array, it is converted into a comma-separated list.

Syntax:

TypoScript Syntax
lib.foo.data = context:<aspectName>:<propertyName>
Example:

Retrieve current workspace id:

EXT:site_package/Configuration/TypoScript/setup.typoscript
page.10 = TEXT
page.10.data = context:workspace:id
page.10.wrap = You are in workspace: |

current

getText Key:

current

Description:

current (gets the "current" value)

Example:

Get the current value:

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = current

date

getText Key:

date

Description:

Can be used with a colon and date-conf.

Default:

d/m Y

Example:

Get the current time formatted dd-mm-yy:

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = date : d-m-y

DB

getText Key:

DB

Syntax:

DB : [table name] : [uid] : [field]

Description:

Value from database. Any record from a table in TCA can be selected here. Records marked as deleted will not return any value.

In contrast to other keys, colons are used here to get deeper into the structure, instead of pipes.

Example:

Get the value of the header field of record with uid 234 from table tt_content:

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = DB : tt_content:234:header

Get the value of the header field of a record, whose uid is stored in a GET parameter myContentId:

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data.dataWrap = DB : tt_content:{GP : myContentId}:header

Note

It is safe to directly use a client-/user-provided input for the id of a DB record here. The function ContentObjectRenderer->getData internally calls the function PageRepository->getRawRecord, which converts the parameter to int via QueryBuilder->createNamedParameter

debug

getText Key:

debug

Description:

Returns HTML-formatted content of the PHP variable defined by the keyword. Available keywords are rootLine, fullRootLine, data, register and page.

Example:

Outputs the current root-line visually in HTML:

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = debug : rootLine

field

getText Key:

field

Syntax:

field : [field name from the current $cObj->data array in the cObject, multi-dimensional.]

Description:

This gives read access to the current value of an internal global variable determined by the given key.

  • As default the $cObj->data array is $GLOBALS['TSFE']->page (record of the current page)

  • In TMENU $cObj->data is set in a loop to the page-record for each menu item during its rendering process.

  • In CONTENT / RECORDS $cObj->data is set to the actual record

  • In GIFBUILDER $cObj->data is set to the data GIFBUILDER is supplied with.

Examples:

Get content from $cObj->data['header']:

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = field : header

Get content from $cObj->data['fieldname']['level1']['level2']:

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = field : fieldname|level1|level2

file

getText Key:

file

Syntax:

file : [uid] : [property]

Description:

Retrieves a property from a file object (FAL) by identifying it through its sys_file UID. Note that during execution of the FILES cObject, it's also possible to reference the current file with "current" as UID like file : current : size.

The following properties are available: name, uid, originalUid, size, sha1, extension, mimetype, contents, publicUrl, modification_date, creation_date

Furthermore when manipulating references (such as images in content elements or media in pages), 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, alternative.

Additionally, any data in the "sys_file_metadata" table can be accessed too.

See the FILES cObject for usage examples.

Example:

Get the file size of the file with the sys_file UID 17:

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = file : 17 : size

flexform

getText Key:

flexform

Syntax:

flexform : [field containing flexform data].[property of this flexform]

Description:

Access values from flexforms, e.g. inside of tt_content record. In contrast to most parts, deeper levels are accessed through dots, not pipes.

Example:

Return the flexform value of given name:

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = flexform : pi_flexform:settings.categories

fullRootLine

getText Key:

fullRootLine

Syntax:

fullRootLine : [pointer, integer], [field name], ["slide"]

Description:

This property can be used to retrieve values from "above" the current page's root. Take the below page tree and assume that we are on the page "Here you are!". Using the levelfield property, it is possible to go up only to the page "Site root", because it is the root of a new (sub-)site. With fullRootLine it is possible to go all the way up to page tree root. The numbers between square brackets indicate to which page each value of pointer would point to:

- Page tree root [-2]
|- 1. page before [-1]
   |- Site root (root template here!) [0]
      |- Here you are! [1]

A "slide" parameter can be added just as for the levelfield property.

Example:

Get the title of the page right before the start of the current website:

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = fullRootLine : -1, title

getenv

getText Key:

getenv

Description:

Value from PHP environment variables.

For a cached variation of this feature, please refer to getEnv.

Example:

Get the env var HTTP_REFERER:

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = getenv : HTTP_REFERER

getIndpEnv

getText Key:

getIndpEnv

Syntax:

getIndpEnv : <name>

Description:

Returns the value of a System Environment Variable denoted by name regardless of server OS, CGI/MODULE version etc. The result is identical to the $_SERVER variable in most cases. This method should be used instead of getEnv to get reliable values for all situations. The internal processing is handled by TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv()

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:
EXT:site_package/Configuration/TypoScript/setup.typoscript
# get and output the client IP
page = PAGE
page.10 = TEXT
page.10.stdWrap.data = getIndpEnv : REMOTE_ADDR
page.10.stdWrap.htmlSpecialChars = 1

global

getText Key:

global

Syntax:

global : [variable]

Description:

Deprecated, use GP, TSFE or getenv.

GP

getText Key:

GP

Syntax:

GP : [Value from GET or POST method]

Description:

Get an variable from $_GET or $_POST where a variable, which exists in both arrays, is returned from $_POST.

Examples:

Get input value from query string &stuff=...

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = GP : stuff

Get input value from query string &stuff[bar]=...

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = GP : stuff|bar

level

getText Key:

level

Description:

Get the root line level of the current page.

Example:

Get the root line level of the current page:

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = level

levelfield

getText Key:

levelfield

Syntax:

levelfield : [pointer, integer], [field name], ["slide"]

Description:

levelfield: Like leveltitle, leveluid, levelmedia et al. but where the second parameter is the root line field to fetch.

Example:

Get the value of the user defined field user_myExtField in the root line. Requires additional configuration in $GLOBALS['TYPO3_CONF_VARS']['FE']['addRootLineFields'] to include field. In order that you can use this function, your fieldname 'user_myExtField' needs be included in the comma separated list of ['addRootLineFields']:

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = levelfield : -1, user_myExtField, slide

leveltitle, leveluid, levelmedia

getText Key:

leveltitle, leveluid or levelmedia

Syntax:

leveltitle, leveluid, levelmedia: [levelTitle, uid or media in root line, 0- , negative = from behind, " , slide" parameter forces a walk to the bottom of the root line until there's a "true" value to return. Useful with levelmedia.]

Description:

Returns values from up or down the page tree.

Examples:

Get the title of the page on the first level of the root line:

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = leveltitle : 1

Get the title of the page on the level right below the current page AND if that is not present, walk to the bottom of the root line until there's a title:

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = leveltitle : -2, slide

Get the id of the root-page of the website (level zero):

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = leveluid : 0

LLL

getText Key:

LLL

Description:

LLL: Reference to a locallang (xlf, xml or php) label. Reference consists of [fileref]:[labelkey]

Example:

Get localized label for logout button:

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = LLL : EXT:felogin/pi1/locallang.xlf:logout

page

getText Key:

page

Description:

page: [field in the current page record]

Example:

Get the current page title:

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = page : title

pagelayout

getText Key:

pagelayout

Description:

pagelayout

Example:

Get the current backend layout:

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = pagelayout

parameters

getText Key:

parameters

Syntax:

parameters: [field name from the current $cObj->parameters array in the cObject.]

Description:

See parseFunc.

Example:

Get content from $cObj->parameters['color']:

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = parameters : color

path

getText Key:

path

Description:

Path to a file, possibly placed in an extension, returns empty if the file does not exist.

Example:

Get path to file rsaauth.js (inside extension rsaauth) relative to siteroot:

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = path : EXT:rsaauth/resources/rsaauth.js

register

getText Key:

register

Syntax

register: [field name from the $GLOBALS['TSFE']->register]

Description:

See LOAD_REGISTER.

Example:

Get content from $GLOBALS['TSFE']->register['color']:

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = register : color

session

getText Key:

session

Syntax:

session : [key]

Description:

The key refers to the session key used to store the value.

Example:

Get the number of items of a stored shopping cart array/object:

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = session : shop_cart|itemCount

site

Data type:

site

Description:

Accessing the current site configuration.

Possible values:

Value

Effect

attributes

Additional parameters configured for this site

base

The Base URL for this site

baseVariants

The Base Variants for this site

rootPageId

The Root Page ID of this site

identifier

The identifier (name) of this site configuration

websiteTitle

The website title of this site

Example:

Code:

Example:

page.10 = TEXT
page.10.data = site:base
page.10.wrap = This is your base URL: |

Where site is the keyword for accessing an aspect, and the following parts are the configuration key(s) to access.

data = site:customConfigKey.nested.value

siteLanguage

Data type:

siteLanguage

Description:

Accessing the current site language configuration.

Possible values:

Value

Effect

attributes

Additional parameters configured for this site language

base

The Base URL for this language

direction

The direction for this language

flagIdentifier

The flag key (like "gb" or "fr") used to be used in TYPO3's Backend.

hreflang

Language tag for this language defined by RFC 1766 / 3066 for "lang" and "hreflang" attributes

languageId

The language mapped to id of the site languge, as defined in the config.yaml languageId

locale

Locale, like 'de_CH' or 'en_GB'

navigationTitle

Label to be used within language menus

title

Label to be used within TYPO3 to identify the language

twoLetterIsoCode

The iso code for this language (two letter) ISO-639-1

typo3Language

Prefix for TYPO3's language files "default" for english, otherwise one of TYPO3's internal language keys. Previously configured via TypoScript config.language = fr

websiteTitle

The website title for this language. No automatic fallback to the site:websiteTitle!

Example:

Code:

EXT:site_package/Configuration/TypoScript/setup.typoscript
page.10 = TEXT
page.10.data = siteLanguage:navigationTitle
page.10.wrap = This is the title of the current site language: |

page.10 = TEXT
page.10.dataWrap = The current site language direction is {siteLanguage:direction}

# Website title for the current language with fallback to the website title of the site configuration.
page.10 = TEXT
page.10.data = siteLanguage:websiteTitle // site:websiteTitle

TSFE

getText Key:

TSFE

Syntax:

TSFE: [value from the $GLOBALS['TSFE'] array, multi-dimensional]

Description:

Returns a value from TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController.

Example:

Get the "username" field of the current FE user:

EXT:site_package/Configuration/TypoScript/setup.typoscript
lib.foo.data = TSFE : fe_user|user|username