Attention

TYPO3 v9 has reached its end-of-life September 30th, 2021 and is not maintained by the community anymore. Looking for a stable version? Use the version switch on the top left.

You can order Extended Long Term Support (ELTS) here: TYPO3 ELTS.

Add TypoScript in your extension

Note

This part is written for extension developers.

Create TypoScript files in your extension

TypoScript files should have the ending .typoscript.

They are located in Configuration/TypoScript within your extension.

Usually, you will have the following structure:

Configuration/
└── TypoScript
    ├── constants.typoscript
    └── setup.typoscript
  • constants.typoscript contains the constants

  • setup.typoscript contains the TypoScript setup

Make TypoScript available for static includes

Configuration/TCA/Overrides/sys_template.php:

<?php
defined('TYPO3_MODE') || die();

call_user_func(function()
{
   $extensionKey = 'myextension';

   /**
    * Default TypoScript
    */
   \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile(
      $extensionKey,
      'Configuration/TypoScript',
      'Some descriptive title'
   );
});

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.

Tip

You may also want to make several different templates available.

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 Make TypoScript available for static includes.

ext_localconf.php:

defined('TYPO3_MODE') || die();

call_user_func(function()
{
   $extensionKey = 'myextension';

   \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScript(
      $extensionKey,
      'setup',
      "@import 'EXT:myextension/Configuration/TypoScript/setup.typoscript'"
   );
});

More information