General developer forum

Simple Plugin that Loads AMD JavaScript

 
Picture of Ryan Carpenter
Simple Plugin that Loads AMD JavaScript
 

I'm trying to build a Moodle plugin that does two things:

  1. Establishes a settings page for admins
  2. Runs a JavaScript file each time a user views a new page.

I've been able to create block plugins that run JavaScript, but I don't want my plugin to have to be added to a specific place or to take up space on the sidebar.

Can anyone point me toward a different plugin template that covers the two requirements above?  Alternatively, what function can I use to hook into the page rendering and add in my code?  Something like this?

local_myplugin_extend_navigation() {
  global $PAGE;
  $PAGE->requires->js_call_amd('local_myplugin/scriptname', 'init');
}

 
Average of ratings: -
Me!
Re: Simple Plugin that Loads AMD JavaScript
 
Average of ratings: -
Picture of Ryan Carpenter
Re: Simple Plugin that Loads AMD JavaScript
 

I found this page in the documentation that helped me on the right track.  The other trick was to add a new admin_settingpage for the plugin, since $settings is not automatically defined for local plugins.

 
Average of ratings: -