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

时间:2011-05-06 18:03:17

标签: moodle

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

2 个答案:

答案 0 :(得分:17)

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

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

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

然后在你的代码中:

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

需要在您的路径上放置moodle_url()

答案 1 :(得分:0)

     <?php 
         //you have load $CFG , firstly check in config.php
         //after that print_r($CFG);
         //also you can use $CFG->wwwroot;

   require ('../config.php');
    require_once ($CFG->dirroot.'/login/lib.php');

//and then in your code:// after that
echo $OUTPUT->header(); ?>


<script src="<?php $CFG->wwwroot ?>/js/jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="<?php $CFG->wwwroot ?>js/jquery.validationEngine-en.js"    type="text/javascript" charset="utf-8"></script>
<script src="<?php $CFG->wwwroot ?>js/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>
<?php $PAGE->requires->js(new moodle_url($CFG->wwwroot.'/blocks/your_block/script.js')); ?>