TYPO3: How could I add css and js files via controller initialize action and page renderer?

一世执手 提交于 2019-11-29 12:36:13

Notice that there is a different approach available in TYPO3 v8 using the HeaderAssets and FooterAssets sections in your template. Thus your action template could look like this:

Your template code

<f:section name="FooterAssets">
  <link rel="stylesheet" href="{f:uri.resource(path: 'Css/ext_booking_manager.css')}"/>
  <script src="{f:uri.resource(path: 'Js/ext_booking_manager.min.js')}"></script>
</f:section>

This way you don't need any resource logic in your controller, thus your initializeAction() method can be dropped.

BTW: I'd recommend using JavaScript as directory name for JavaScript resources to stay in line with TYPO3 conventions.

In TYPO3 8 getPageRenderer() Method is Deprecated. You can see here Deprecated Methods.

Now you can use this methods in TYPO3 8 Like this solution

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