Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to load external JS file into moodle?

Tags:

moodle

how to load external JS file into moodle ? using moodle api ,i.e moodle libraries ..

like image 817
shox Avatar asked May 06 '11 18:05

shox


1 Answers

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!

like image 187
Anatai Avatar answered Oct 19 '22 11:10

Anatai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!