how to load external JS file into moodle ? using moodle api ,i.e moodle libraries ..
In Moodle 2.0 I have always used $PAGE->requires->js()
.
To start with, make $PAGE
available to your code by doing:
require_once($CFG->libdir . '/pagelib.php');
global $PAGE;
and then in your code:
$PAGE->requires->js( new moodle_url($CFG->wwwroot . '/blocks/your_block/script.js') );
It is required to put moodle_url()
around your path!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With