Access TypoScript in an extension
Note
This part is written for extension developers.
This page explains how to access TypoScript settings in an extension.
Extbase controllers
In Extbase controllers,
Flexform settings and TypoScript settings will be
merged together. If settings exists in both, the Flexform takes precedence and overrides the TypoScript setting.
Note that both Flexform and TypoScript settings must use the convention of preceding the setting with
settings.
(for example,
settings.).
Extbase offers some advantages: Some things work automatically out-of-the-box. However, you must stick to the Extbase conventions ("conventions over configuration").
In order to access TypoScript settings from an Extbase controller.
-
Use the convention of defining your TypoScript settings in
settingsEXT:my_extension/Configuration/TypoScript/setup.typoscriptplugin.tx_myextension { view { # view settings } settings { key1 = value1 key2 = value2 } }Copied! -
Access them via
$this->settingsFor example, in your controller:
$myvalue1 = $this->settings['key1'] ?? 'default';Copied!
See also
Fluid
If Extbase controllers are used,
$this->settings
is automatically passed to the
Fluid template. Allowing you to access settings like this:
{settings.key1}
Without Extbase, a template rendered by the FLUIDTEMPLATE content object receives its settings from the settings property of that content object.
Reading frontend TypoScript from the PSR-7 request
Any class that can reach the PSR-7 request — a content object, a middleware, an event listener — reads the parsed frontend TypoScript from the frontend.typoscript request attribute:
$fullTypoScript = $request->getAttribute('frontend.typoscript')
->getSetupArray();
Note
\TYPO3\
throws a
Runtime when the frontend was fully
served from the page cache, because the setup is not parsed in that
case. Content objects are not affected: whenever they are calculated,
the setup is available.
See also
Reading page TSconfig
Page TSconfig is backend TypoScript and therefore not part of the frontend
request. It is read for a single page with
Backend, which returns the parsed TypoScript
as an array.
See also