如何将外部JS文件加载到moodle中?

如何将外部JS文件加载到moodle中?

问题描述:

如何将外部JS文件加载到moodle中?使用moodle api,即moodle库..

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

在 Moodle 2.0 中我一直使用 $PAGE->requires->js().

In Moodle 2.0 I have always used $PAGE->requires->js().

首先,通过执行以下操作使 $PAGE 可用于您的代码:

To start with, make $PAGE available to your code by doing:

require_once($CFG->libdir . '/pagelib.php');
global $PAGE;

然后在您的代码中:

$PAGE->requires->js( new moodle_url($CFG->wwwroot . '/blocks/your_block/script.js') );

需要在你的路径周围加上moodle_url()

It is required to put moodle_url() around your path!