How to add javascript to all pages in silverstripe cms via a module?

六月ゝ 毕业季﹏ 提交于 2020-07-10 10:25:30

问题


I am trying to create a module for silverstripe. I am going through https://docs.silverstripe.org/en/4/developer_guides/templates/requirements/#requirements to understand how to add javascript and css files to the front end pages.

What I am not able to figure out is how to add a javascript file to all cms pages when the user installs my module. Is there a class I can extend and specify there? Or can it be done using the config somehow?


回答1:


Create a class that subclasses SilverStripe\Core\Extension, and then apply it to \PageController using a config YML file

Your Extension class can then implement onAfterInit() to use the Requirements API




回答2:


We can do this by adding the following to a .yml file:

SilverStripe\Admin\LeftAndMain:
  extra_requirements_javascript:
    - your-namespace/your-module-name:javascript/file.js


来源:https://stackoverflow.com/questions/62808724/how-to-add-javascript-to-all-pages-in-silverstripe-cms-via-a-module

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