Adding page-specific Javascript to each view in CakePHP

前端 未结 9 1186
余生分开走
余生分开走 2020-12-28 09:35

In an attempt to keep my scripts maintainable, I\'m going to move each into their own file, organised by controller and action:

// scripts which only apply t         


        
9条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-28 09:43

    I just had to do page specific inclusion, but I've found a neater way to do it in the documentation. You can just load it into some script block in your default.ctp. And in corresponding view just use HTML helper to push a script:

    You can append the script tag to a specific block using the block option:

    echo $this->Html->script('wysiwyg', array('block' => 'scriptBottom'));
    

    Which appends to a block.

    In your layout you can output all the script tags added to ‘scriptBottom’:

    echo $this->fetch('scriptBottom');
    

提交回复
热议问题