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
vhs:asset
? (Only using version 7, not sure if vhs:asset is still a way to go in version 8). I use vhs:asset to merge some CSS files together. And to load some other CSS files only when I use a specific template/plugin – nbar