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

前端 未结 2 643
悲哀的现实
悲哀的现实 2020-12-11 10:02

I am using the new page renderer from TYPO3 8 on controller level to add extension specific css and js files via an initializeAction:

public function initial         


        
相关标签:
2条回答
  • 2020-12-11 10:44

    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.

    0 讨论(0)
  • 2020-12-11 10:49

    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

    0 讨论(0)
提交回复
热议问题