DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • When Angular APIs Return 200 but the Frontend Is Already Failing Users
  • 5 Layers of Prompt Injection Defense You Can Wire Into Any Node.js App
  • Boosting React.js Development Productivity With Google Code Assist
  • Why Angular Performance Problems Are Often Backend Problems

Trending

  • DZone's Article Submission Guidelines
  • DevOps Is Dead, Long Live Platform Engineering
  • Retesting Best Practices for Agile Teams: A Quick Guide to Bug Fix Verification
  • Observability in Spring Boot 4
  1. DZone
  2. Coding
  3. JavaScript
  4. Adding External JavaScript Files (.js) Into Moodle

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.

By 
Ranjith Udayakumar user avatar
Ranjith Udayakumar
·
Feb. 18, 19 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
18.9K Views

Join the DZone community and get the full member experience.

Join For Free

You 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

  1. Go inside your “/theme/YourThemeName” folder. If you don’t have “javascript” folder inside “/theme/YourThemeName”, create a new folder called “javascript”.
  2. Inside the new javascript folder that you have created, upload the .js files.
  3. 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.

Related

  • When Angular APIs Return 200 but the Frontend Is Already Failing Users
  • 5 Layers of Prompt Injection Defense You Can Wire Into Any Node.js App
  • Boosting React.js Development Productivity With Google Code Assist
  • Why Angular Performance Problems Are Often Backend Problems

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook