TypoScript

By convention all TypoScript, that can be included manually, should be stored in the folder EXT:my_extension/Configuration/TypoScript/.

TypoScript constants should be stored in a file called constants.typoscript and TypoScript setup in a file called setup.typoscript.

TypoScript folder
$ tree packages/my_extension/Configuration/TypoScript/
├── constants.typoscript
└── setup.typoscript
Copied!

These two files will be included via ExtensionManagementUtility::addStaticFile in the file Configuration/TCA/Overrides/sys_template.php:

EXT:my_extension/Configuration/TCA/Overrides/sys_template.php
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile(
    'my_extension',
    'Configuration/TypoScript/',
    'Examples TypoScript'
);
Copied!

If there should be more then one set of TypoScript templates that may be included, you can use store them in sub folders.

If your TypoScript is complex and you need to break it up into several files you should use the ending .typoscript for these files.

TypoScript folder, extended
$ tree packages/my_extension/Configuration/TypoScript/
├── Example1
│    ├── constants.typoscript
│    └── setup.typoscript
├── SpecialFeature2
│    ├── Setup
│    │    ├── SomeIncludes.typoscript
│    │    └── OtherIncludes.typoscript
│    ├── constants.typoscript
│    └── setup.typoscript
├── constants.typoscript
└── setup.typoscript
Copied!

In this case ExtensionManagementUtility::addStaticFile needs to be called for each folder that should be available in the TypoScript template record:

EXT:my_extension/Configuration/TCA/Overrides/sys_template.php
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile(
    'my_extension',
    'Configuration/TypoScript/',
    'My Extension - Main TypoScript'
);

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile(
    'my_extension',
    'Configuration/TypoScript/Example1/',
    'My Extension - Additional example 1'
);

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile(
    'my_extension',
    'Configuration/TypoScript/SpecialFeature2/',
    'My Extension - Some special feature'
);
Copied!