Adding External JavaScript Files (.js) Into Moodle
We're huge fans of open source and knowledge sharing. Read on to learn how to upload your JS files (and knowledge) to the open-source Moodle learning platform.
Join the DZone community and get the full member experience.
Join For FreeYou may wonder how to add custom JavaScript files into Moodle. I had the same question. So, I am writing this article to share how I made it through and ease your process with an example.
Steps
- Go inside your “/theme/YourThemeName” folder. If you don’t have “javascript” folder inside “/theme/YourThemeName”, create a new folder called “javascript”.
- Inside the new javascript folder that you have created, upload the .js files.
- Next, go inside your “/theme/YourThemeName/config.php”. At the very bottom of the file, add a new line of code to include our javascript files.
#To load the js files in your header:
$THEME->javascripts = array(‘yourfirstjsfile’,’yoursecondjsfile’);
#To load the js files in your footer:
$THEME->javascripts_footer = array(‘yourfirstjsfile’,’yoursecondjsfile’);
4. In order to see the changes, the caches of the site must be purged. Clear the browser cache and refresh to see the changes.
Note: Add the JS files in the config without specifying the extension.As “yourfirstjsfile” not like “yourfirstjsfile.js”
JavaScript
Opinions expressed by DZone contributors are their own.
Comments