Search code examples
typo3typoscript

TYPO3 v10: How to access TSFE in Backend/Scheduler Task?


The current situation:
I am trying to access the TypoScript configuration of the frontend from within the backend (or rather a scheduler task). Previously with Typo3 v8 and v9, I initialized entire $GLOBALS["TSFE"] object, however this was already hack the last time around (using mostly deprecated calls) and now it has all been removed with the v10 release.

My goal:
Access the TypoScript configuration of the frontend of a certain page (root page of a site would be fine) from within a scheduler job.

Background of the whole project:
I have a periodic scheduler job that sends emails to various users (fe_users). The email contains links to certain pages (configured UIDs in typoscript) as well as file attachments and the likes (generated by other extensions, which are also fully configured via typoscript). Currently, I basically initialize the entire frontend from within the backend, but as I said before, its inefficient, super hacky and I doubt it was the intended way to solve this problem.


Solution

  • Getting TypoScript settings in the backend is ugly, but possible.

    You need a page ID and a rootline which you can pass to \TYPO3\CMS\Core\TypoScript\TemplateService::runThroughTemplates().

    Something along these lines:

    $template = GeneralUtility::makeInstance(TemplateService::class);
    $template->tt_track = false;
    $rootline = GeneralUtility::makeInstance(
      RootlineUtility::class, $pageId
    )->get();
    $template->runThroughTemplates($rootline, 0);
    $template->generateConfig();
    $typoScriptSetup = $template->setup;
    

    You can get inspiration from \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::getTypoScriptSetup and \TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateObjectBrowserModuleFunctionController