Add TypoScript in your extension¶
Changed in version 13.1
TypoScript on a per-site basis can now be included via sites and sets.
Note
This part is written for extension developers.
Create TypoScript files in your extension¶
TypoScript files must have the ending .typoscript
.
They are located in Configuration/
within your
extension. Read more about how to
provide the TypoScript as set for TYPO3 v13 and above
and how to provide TypoScript for both TYPO3 v13 and v12.
constants.
contains the constantstyposcript setup.
contains the TypoScript setuptyposcript
TypoScript provided as site set (only TYPO3 v13.1 and above)¶
The file structure of the extension could, for example look like this:
-
-
...
-
-
-
-
-
...
-
-
composer.json
-
...
With the extension's TypoScript residing in EXT:
and the TypoScript for some optional feature in
EXT:
. Let us assume, that the
optional feature depends on the main TypoScript.
The sets can now be defined for TYPO3 v13 as follows:
The main set of the extension¶
The sub set for an optional feature¶
TypoScript files provided by the sets¶
The TypoScript placed in the same folder like the set, contains your configurations.
TypoScript provided by extensions supporting TYPO3 v12.4 and v13¶
When an extension provides TypoScript and should be compatible with both
TYPO3 v12.4 and v13, you can provide site sets but still support including
the TypoScript in the sys_
record via static_
's.
The files in the sets are the same as in the example for TYPO3 v13 only.
The extended file structure of the extension could, for example look like this:
-
-
...
-
-
-
-
-
-
Overrides
sys_template.php
-
-
-
-
...
-
-
composer.json
-
...
Only when supporting TYPO3 v12.4: Make TypoScript available for static includes¶
Make TypoScript available for static includes (only needed if your extensions aims to support TYPO3 v12.4):
<?php
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
defined('TYPO3') or die();
call_user_func(function () {
$extensionKey = 'my-extension';
$versionInformation = GeneralUtility::makeInstance(Typo3Version::class);
if ($versionInformation->getMajorVersion() < 13) {
ExtensionManagementUtility::addStaticFile(
$extensionKey,
'Configuration/Sets/MyExtension',
'My Extension, main TypoScript, always include',
);
ExtensionManagementUtility::addStaticFile(
$extensionKey,
'Configuration/Sets/MyExtensionWithACoolFeature',
'My Extension, Cool feature',
);
}
});
If you include the TypoScript this way, it will not be automatically loaded. You MUST load it by adding the static include in the Web > Template module in the backend, see Include TypoScript from extensions. This has the advantage of better configurability.
This will load your constants and your setup once the template is included statically.
Make TypoScript available (always load)¶
Only do this, if your TypoScript must really be always loaded in your site. If this is not the case, use the method described in the previous section TypoScript provided as site set (only TYPO3 v13.1 and above).
<?php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3') or die();
ExtensionManagementUtility::addTypoScript(
'my_extension',
'setup',
"@import 'EXT:my_extension/Configuration/TypoScript/setup.typoscript'",
);
It is also possible to put your TypoScript in a file called ext_typoscript_setup.typoscript or ext_typoscript_constants.typoscript (for constants).
More information¶
- TypoScript configuration (in "Sitepackage Tutorial")`
- Extension Configuration (in "Sitepackage Tutorial")`