Reputation: 3498
I used to load a css file when my extension gets loaded like this in 7LTS:
/**
* Init
*
* @return void
*/
public function initializeAction() {
$GLOBALS['TSFE']->getPageRenderer()->addCssFile('typo3conf/ext/myextension/Resources/Public/Css/myextension.css');
}
In 8LTS I get an error:
Uncaught TYPO3 Exception Call to undefined method TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::getPageRenderer()
Supposedly getPageRenderer() is depcreciated:
How can I load a css file when my extension gets loaded now?
I tried this but it's not working:
/**
* Init
*
* @return void
*/
public function initializeAction() {
$pageRender = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\PageRenderer::class);
$pageRender->addCssFile('typo3conf/ext/myextension/Resources/Public/Css/basic.css');
}
The duplicate link describes an alternative way (via templating) ... but not via an action ... so in my opinion no duplicate
Upvotes: 2
Views: 759
Reputation: 7939
The PageRenderer itself is not deprecated, just the method ->getPageRenderer()
as the PageRenderer is now a Singleton.
So what you do is
$pageRenderer = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\PageRenderer::class);
and you are fine.
Upvotes: 2