TYPO3 - 在8LTS中加载扩展时,在init上加载css文件? getPageRenderer()已折旧

时间:2017-08-22 13:50:56

标签: typo3 typo3-8.x

当我的扩展程序在7LTS中加载时,我曾经加载了一个css文件:

/**
 * Init
 *
 * @return void
 */
public function initializeAction() {

    $GLOBALS['TSFE']->getPageRenderer()->addCssFile('typo3conf/ext/myextension/Resources/Public/Css/myextension.css');

}

在8LTS中我收到错误:

未捕获TYPO3例外 调用未定义的方法TYPO3 \ CMS \ Frontend \ Controller \ TypoScriptFrontendController :: getPageRenderer()

据说getPageRenderer()已被删除:

https://docs.typo3.org/typo3cms/extensions/core/8.7/Changelog/8.0/Breaking-72424-RemovedDeprecatedTypoScriptFrontendControllerOptionsAndMethods.html?highlight=getpagerenderer

如何立即加载扩展程序时加载css文件?

我尝试了这个,但它不起作用:

/**
 * 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');       

}

重复链接描述了一种替代方式(通过模板化)......但不是通过动作...所以在我看来没有重复

1 个答案:

答案 0 :(得分:2)

PageRenderer本身已弃用,只是方法->getPageRenderer(),因为PageRenderer现在是Singleton。

所以你做的是 $pageRenderer = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\PageRenderer::class);你很好。