Load Javascript files in CakePHP Layout at “bottom”

后端 未结 2 832
野性不改
野性不改 2021-02-08 08:52

Currently, I have a big CakePHP application with a layout and a lot of views. In the layout, I load Javascript files in the head which are needed by most views. In the views the

相关标签:
2条回答
  • 2021-02-08 09:17

    Since CakePHP version 2.1 you can use script blocks:

    // in your view
    $this->Html->script('filename', array('block' => 'scriptBottom'));
    
    // in your layout
    echo $this->fetch('scriptBottom');
    

    This approach lets you keep echo $this->fetch('script') in the <head> of your layout in case you need any scripts at the top.

    0 讨论(0)
  • 2021-02-08 09:27

    This is what I do in my view:

    echo $this->Html->script('filename', array('inline' => false));
    

    And this is what I do at the bottom of my layout:

    echo $this->fetch('script');
    
    0 讨论(0)
提交回复
热议问题