As you might know it is possible to store typoscript into files. You include them in your templates using this line:

<INCLUDE_TYPOSCRIPT: source="FILE: fileadmin/filename.ts">

In my opinion this is a very good way to organise your templates. I would even go a step further and create a custom extension for every project and store the typoscript there. Generally I follow two principles whereever it is possible:

  1. Files vs database: Content goes into the database. Everything else goes into files. That means PHP code, css and typoscript should not be stored into database records. See below for some good reasons why this should be done.

  2. Extensions vs fileadmin: Editor/customer generated stuff should go into fileadmin/. Everything else goes into extensions. Even the html templates, layout images and the css should go into an own extension. Of course the customer should be able to override those settings (like exchanging a header image) if this is required. Those files go into fileadmin of course.
    Group your typoscript into static files. This makes it even easier to include them into the TYPO3 instance.

Storing typoscript into files has a lot of advantages:

  1. They are versionable. Configuration and other structural information should be versionable, revertable, diffable. Database can not be handeld in such an easy way.

  2. Deployment is easier. In setup where developers have their own copy of a TYPO3 instance to work on, their changes need to be merged with other instances. Doing this with database content is not an easy task and cannot be done without a time-consmuing manual process. Updating some files is independent from the content (which is in the database).
    Especially when using automatic builds (e.g. when using a continuous integration server) it's easier to get your structural changes from files instead from database content (where typoscript would conflict with content and other user data).

  3. Development is easier. Handling files is always easier than handling database records. You can edit them in your favourite editor or IDE. You can use wide spread tools for common tasks like searching and replacing. You can access files easily remotely via ftp and ssh.

  4. Reuse your typoscript. Typoscript stored in files is easier to be reused. Build your own typoscript library extension with snippets you'll use in other projects and reuse this extension everywhere.

Of course there is always the problem that you expose sensitive data to the public by storing them into files that are accessible by default. Protect them by forbidding downloads in your apache configuration or protect them by giving them the php file extension and adding following line as the first line:

# <?php die(); ?> = TEXT ...

This is valid php and valid typoscript code. Saving your typoscript files as *.ts.php files will make Apache interpret them (and die immediately) instead of sending the file content to the browser.

Another best practice is to always name the files like the most top level typoscript layer. E.g. the file plugin.tx_myext_controller_foo.ts.php should only contain typoscript in:

plugin.tx_myext_controller_foo { }

Include statements can be nested. So you'll be able to organize complex setups this way too. A good idea might also be to use your extension's static template's setup.txt file to include your typoscript files located in EXT:your_ext/typoscript. This way you have the maximum flexibility to develop your extension's typoscript without the need to make changes to the TYPO3 instance after updating or adding new parts (beside clearing the cache).

Where do you store your typoscript? Any best practices? Other advantages of storing it into files? Any disadvantages doing it this way? Feel free to add some comments here...


This website uses disqus for the commenting functionality. In order to protect your privacy comments are disabled by default.

Enable Comments