问题
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