Search code examples
typo3typo3-9.x

TYPO3 9.5 Include a TypoScript File for all Backend pages


I did write a Typo3 Extension called 'locationgallery' with a backend Module. This backend module should use the following TypoScript configuration.

module.tx_locationgallery_web_locationgallerylocationgallerybe {
    view {
        templateRootPaths.0 = EXT:locationgallery/Resources/Private/Backend/Templates/
        partialRootPaths.0 = EXT:locationgallery/Resources/Private/Backend/Partials/
        layoutRootPaths.0 = EXT:locationgallery/Resources/Private/Backend/Layouts/
    }
}

If I now include the static template of 'locationgallery', that was added via ExtensionManagementUtility::addStaticFile, anything works fine on each page where this template is included.

My problem is, that I get the error message

Sorry, the requested view was not found.

The technical reason is: No template was found. ...

if I select a page in the page tree where the static template is not included.

My problem now is that I do not want to include the static template in the root page, but the backend module of 'locationgallery' needs to be usable on all pages.

I did try to include the corresponding parts of the configuration using ExtensionManagementUtility::addPageTSConfig, that is used to add TSConfig to the $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'] variable. But this Typoscript is not interpreted before the view tries to find the template. (E.g. it is not interpreted at all during this run, as far as I know, because I found only TemplateService::mergeConstantsFromPageTSconfig and TypoScriptFrontendController::getPagesTSconfig referring to $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'].)

I found that powermail archived what I want by using ext_typoscript_setup.typoscript, but this is deprecated according to https://forge.typo3.org/issues/52364.

An additional drawback of this method is that 'ext_typoscript_setup.typoscript' is interpreted independent of backend and frontend mode.

I would like to know if there is any non deprecated method to include some TypoScript for any backend run in Typo3.

Thanks for any suggestions.


Solution

  • You can split your TS setup into several files to seperate the includes.

    Add the following methods in Configuration/TCA/Overrides/sys_template.php

    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile(
      'your_ext_key',
      'Configuration/TypoScript/backend_or_however_you_call_it.typoscript',
      'Your label'
    );
    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile(
      'your_ext_key',
      'Configuration/TypoScript/frontendend_or_however_you_call_it.typoscript',
      'Your label'
    );