开发者

how to load external JS file into moodle?

how to load external JS fi开发者_如何学编程le 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!


     <?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')); ?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜