Search code examples
configurationtypo3typoscripttypo3-9.x

TYPO3 - Where do i need to put script files to be @imported


In the TYPO3 backend, in the Web -> Template Section, in a template´s Setup text entry, I want to include a typoscript using the @import syntax.

I have setup my local Typo3 v9.5.5 test instance (Windows) inside a folder typo3, which itself is inside of the htdocs folder (it is a XAMPP installation). So the url to the backend is http://localhost/typo3/typo3/index.php, notice the duplication of typo3. The reason is, i have set up a few CMSes in the htdocs folder, each within a folder having the corresponding name.

Where do i have to put the script inside of the typo3 folder, and what would be the correct code line which includes it?

I tried all kind of paths, like @import 'EXT:typo3testsite/TypoScript/playaround.typoscript', and putting the script under htdocs/typo3/TypoScript/playaround.typoscript or under htdocs/typo3/typo3conf/sites/typo3testsite/TypoScript/playaround.typoscript, but no success.

The site ID, set up under Site Managment -> Sites, is typo3testsite.

The script content, for now, is

page = PAGE
page.10 = TEXT
page.10.value = Hello World

When i have cleared constants and setup from parent templates i get Service Unavailable (503). When i put the code directly into the Setup entry it correctly shows 'Hello World' on the front page.


Solution

  • You can do it this way

    # Import a single file
    @import 'EXT:myproject/Configuration/TypoScript/randomfile.typoscript'
    
    # Import multiple files in a single directory, sorted by file name
    @import 'EXT:myproject/Configuration/TypoScript/*.typoscript'
    
    # Import all files in a directory
    @import 'EXT:myproject/Configuration/TypoScript/'
    
    # It's possible to omit the file ending, then "typoscript" is automatically added
    @import 'EXT:myproject/Configuration/TypoScript/'
    

    See New syntax for importing TypoScript files

    The example is useful, when you have an own extension. 'myproject' is then the name of your extension. After 'EXT:' comes the path to the configuration file in your extension.

    If you have never built an own extension: Developing TYPO3 Extensions with Extbase and Fluid