且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

TYPO3:如何通过控制器初始化动作和页面渲染器添加CSS和JS文件?

更新时间:2023-11-08 23:14:40

请注意,TYPO3 v8中使用

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>

这样,您的控制器不需要任何资源逻辑,因此可以删除initializeAction()方法.

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

顺便说一句:我建议使用JavaScript作为JavaScript资源的目录名称,以与TYPO3约定保持一致.

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