You can also add include-instructions in TypoScript code. Availability depends on the context, but it works with TypoScript templates, Page TSconfig and User TSconfig.
Since TYPO3 version 9 a new syntax for importing external TypoScript files has been introduced, which acts as a preprocessor before the actual parsing (condition evaluation) takes place.
Its main purpose is ease the use of TypoScript includes and making it easier for integrators and frontend developers to work with distributed TypoScript files. The syntax is inspired by SASS imports and works as follows:
# Import a single file @import 'EXT:myproject/Configuration/TypoScript/randomfile.typoscript' # Import multiple files of a single directory in file name order @import 'EXT:myproject/Configuration/TypoScript/*.typoscript' # Import all files of a directory @import 'EXT:myproject/Configuration/TypoScript/' # The filename extension can be omitted and defaults to .typoscript @import 'EXT:myproject/Configuration/TypoScript/'
The main benefits of
@import compared to
- is less error-prone
- @import is expressive and self-explanatory
- better clarifies whether files or folders are imported (in comparison to the
The following rules apply:
- Multiple files are imported in alphabetical order.
- Recursion is allowed. Imported files can have
@importstatement does not take a condition clause as the old
<INCLUDE_TYPOSCRIPT condition="">statement did. That kind of condition should be considered a conceptual mistake. It should not be used.
- Both the old syntax
<INCLUDE_TYPOSCRIPT>and the new one
@importcan be used at the same time.
- Directory imports are not recursive, meaning that a directory import does not automatically travel down its subdirectories.
- Quoting the filename is necessary with the new syntax. Either double quotes (“) or single quotes (‘) can be used.
Internals: Under the hood, Symfony Finder is use to find the file and provides the “globbing” feature (* syntax).
The syntax is designed to stay and there are absolutely no plans to
@import statement in the future. However, the
@... syntax for annotations may be used to add more preparsing logic to
TypoScript in future.
Alternative, traditional Syntax¶
A traditional include-instruction will work as well and for example looks like this:
- It must have its own line in the TypoScript template, otherwise it is not recognized.
- It is processed BEFORE any parsing of TypoScript (contrary to conditions) and therefore does not care about the nesting of confinements within the TypoScript code.
The “source” parameter points to the source of the included content. The string before the first “:” (in the example it is the word “FILE”) will determine which source the content is coming from. These options are available:
A reference to a file relative to
Also paths relative to the including file can be
passed to INCLUDE_TYPOSCRIPT, if the inclusion is called from inside a
file. These paths start with
If you use a syntax like
This includes all files from a directory relative to
Files are included in alphabetical. Also files are included first, then directories.
<INCLUDE_TYPOSCRIPT: source="DIR:fileadmin/templates/" extensions="typoscript">
This includes all those files from the directory
Since TYPO3 CMS 7, it is possible to use conditions on include directives. The conditions are the same as was presented in the previous chapter. The files or directories will be included only if the condition is met.
<INCLUDE_TYPOSCRIPT: source="FILE:EXT:my_extension/Configuration/TypoScript/user.typoscript" condition="[loginUser = *]">
The option to filter by extension has been included exactly for the
purpose of covering as many use cases as possible. In TYPO3 CMS we often
have many different ways of configuring something, with pros and cons
and the extended inclusion command serves this purpose of letting you
organize your files with different directories using whichever extension
fits your needs better (e.g.,
.typoscript) and/or filter by extension (e.g.,
because you may have
.txt in the directory or because you prefer
.typoscript<something> as extension).
It is recommended to separate files with different directories:
- For TSconfig code use a directory called TSconfig/, possibly with subdirectories named Page/ for Page TSconfig and User/ for User TSconfig.
- For TypoScript template code, use a directory named TypoScript/.
However, we understand that filtering by extension could make sense in some situations and this is why there is this additional option.