how to include public resources to typo3 extbase extension

邮差的信 提交于 2019-12-06 06:49:16

I'm not sure how you define the template for your backend, but it seems this usually happens using the backend container view helper which already has functions for that:

<f:be.container
  addCssFile="{f:uri.resource(path:'css/style.css')}"
  addJsFile="{f:uri.resource(path:'js/scripts.js')}">

  [your templates content]

</f:be.container>

In TYPO3 7.6.X, It has to be like following

<f:be.container
     includeCssFiles="{style:'{f:uri.resource(path:\'css/style.css\')}'}"
     includeJsFiles="{script:'{f:uri.resource(path:\'js/script.js\')}'}"
    >
<!-- Template Code -->
</f:be.container>

As includeCssFiles and includeJsFiles requires array to be passed, we can include any number of js and css.

i think the problem was my ViewHelper need to renderChilden and start/end page

current implementation is like this

the ViewHelper

namespace Vendor\ExtKey\ViewHelpers;

class AddPublicResourcesViewHelper extends  \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper {

    public function render() {
        $doc = $this->getDocInstance();
        $pageRenderer = $doc->getPageRenderer();
        $extRelPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath("ext_key");

        $pageRenderer->addCssFile($extRelPath . "Resources/Public/css/styles.css");

        $pageRenderer->loadJquery();
        $pageRenderer->addJsFile($extRelPath . "Resources/Public/js/app.js");

        $output = $this->renderChildren();
        $output = $doc->startPage("title") . $output;
        $output .= $doc->endPage();

        return $output;
    }
}

the template

{namespace pager=Vendor\ExtKey\ViewHelpers}
<f:layout name="Default" />

<f:section name="main">
<pager:addPublicResources />

Pagerender::loadJjquery is working and accessible like this

TYPO3.jQuery(function($) {

});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!