Daniel Siepmann - Coding is Art

Blog Post

TypoScript outside of Frontend context

Published: , Updated:

Tested with TYPO3: 11 LTS, 10 LTS, 9 LTS, 8 LTS

Topics: extbase, typo3, typoscript


TypoScript by concept is meant for frontend context only. There is TSconfig for backend as well. Extbase introduced a way to also configure backend modules via TypoScript. Nowadays TypoScript is also used in other context, e.g. scheduler tasks or commands.

I'll explain how the actual TypoScript is loaded, so you understand that part and can use it.

The issue

Let me explain the issue first. Hopefully that will ease understanding of the following sections.

TypoScript by concept is meant for Frontend. That concept didn't change, even if TypoScript now is also used in other context. Therefore, TypoScript is still bound to a concrete page, as each page could load different TypoScript. Even contexts without the concept of a page still need to determine the page to load TypoScript.

That's not an issue for backend modules with page tree component. Whenever a page is selected, that one will be passed as an argument to the URL of the module. That way TYPO3 already has a page to use. But that's not the case if no page is selected, or in context of a command where no page is available at all.

Determining the page

TYPO3 needs to determine the page that defines TypoScript to load. TYPO3 in that context means Extbase. ViewHelpers and other components relying on TypoScript often use Extbase TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface to load TypoScript. I'll explain exactly that implementation:

  1. ConfigurationManager use the concrete configuration manager based on context, which is TYPO3\CMS\Extbase\Configuratio\BackendConfigurationManager for all contexts except frontend.
  2. BackendConfigurationManager first determine the page before loading TypoScript.

The logic to determine the page can be fetched from its getCurrentPageId() method:

  1. Use id parameter of either GET or POST.
  2. Use the first root page. A root page is determined by the following: is_siteroot has to be set, it has to be in default language and should not be within a workspace. "First" means the first one based on sorting.
    Most probably a page was found at this position and is used.

    Humans are not able to determine that in case of nested page trees with root pages on different levels. Those scenarios always force to check the database. That sorting can change at any time, as sorting is based on the actual level. So never relay on that.
  3. Determine first TypoScript record which is defined as root. "First" means the first one created.
  4. Use 0 as page uid.

How to overcome the limitation

I never found a proper way, there is no API. The best suggestion:

Don't use TypoScript in such contexts. If you need TypoScript, for whatever reason, keep it to a minimum, always include it and don't use any features like conditions.

module. vs plugin.

Extbase populates $this->settings within controllers. Extbase uses plugin. in frontend and module. in backend context. Some extensions add module.tx_extname < plugin.tx_extname in order to have the same settings available in both contexts.

That's specific to extension / plugin settings fetched by the API.

Further reading