Search code examples
javascriptphpsilverstripesilverstripe-4

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


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?


Solution

  • 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