3

while upgrading our codebase for 9.5 i just found the old approach with using

$res = $this->response;
$res->addAdditionalHeaderData('<script src="' . $scriptPath . '" type="text/javascript"></script>');

this all happens inside an extension controller extending ActionController, the methods seem not to exist anymore and i cant find the new way of implementing that functionality. so how can i add additional header data inside my action controller from my extbase extension?

help is much appreciated

netzding
  • 772
  • 4
  • 21

2 Answers2

6

we did it with the PageRenderer class which can be instantiated within the ActionController

    /** @var PageRenderer $pageRenderer */
    $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
    $pageRenderer->addHeaderData($additionalHeaderData);
netzding
  • 772
  • 4
  • 21
-1

Since TYPO3 10.4 you have the AssetCollector class to add a Javascript or CSS. I have added this for users who find this topic at a later time.

use TYPO3\CMS\Core\Utility\GeneralUtility;

$assetCollector = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\AssetCollector::class);
$assetCollector->addJavaScript('my_identifier', $scriptPath, [], ['priority' => true]);

The priority must be set to true, in order to get the Javascript include into the header of the html page.

Franz Holzinger
  • 913
  • 10
  • 20