Search This Blog

Wednesday, February 22, 2012

Create an empty page for Moodle

I came across this code in the forum today and I thought it's a nice snippet to keep. This shows how to create a new, blank page within the moodle system.


<?php


// The number of lines in front of config file determine the // hierarchy of files.
require_once(dirname(dirname(__FILE__)).'/../config.php');


$PAGE->set_context(get_system_context());
$PAGE->set_pagelayout('admin');
$PAGE->set_title("Your title");
$PAGE->set_heading("Blank page");
$PAGE->set_url($CFG->wwwroot.'/blank_page.php');


echo $OUTPUT->header();


// Actual content goes here
echo "Hello World";


echo $OUTPUT->footer();
?>

Simple as that!
================================
Update: April 16, 2012

Here is an example of creating a custom file in Moodle:


<?php


require_once(dirname(dirname(__FILE__)).'/../../../config.php');


$PAGE->set_context(get_system_context());
$PAGE->set_pagelayout('admin');
$PAGE->set_title("Your title");
$PAGE->set_heading("Blank page");
$PAGE->set_url($CFG->wwwroot.'/theme/themename/layout/ foldername/moodlepage.php');


$PAGE->requires->js('/theme/themename/layout/ foldername/prettyphoto/js/jquery-1.6.1.min.js', true);
$PAGE->requires->js('/theme/ themename/layout/foldername/Jquery/carouFredSel-5.2.3/jquery.carouFredSel-5.2.3-packed.js', true);
$PAGE->requires->js('/theme/themename/layout/foldername/prettyphoto/js/jquery.prettyPhoto.js', true);
$PAGE->requires->css('/theme/themename/layout/foldername/prettyphoto/css/prettyPhoto.css', true);
$PAGE->requires->css('/theme/themename/layout/foldername/style.css', true);


echo $OUTPUT->header();


include('index.php'); 


echo $OUTPUT->footer();
?>

Sunday, February 12, 2012

Adding Javascript to "page" resource

Well this has been bugging me for a while - every time I tried to insert Javascript into the moodle html editor it never worked. You could embed content with <object> or <iframe> tags....but I'm against that because of display issues on different browsers.

Well I've finally found the simple solution - you need an extra identifier in your javascript.


<script type="text/javascript" language="javascript">
//<![CDATA[
               your code here....
               //]]>
</script>

All you need to do is add the code marked in yellow above, purge your moodle cache and voila! Your javascript now works inside the moodle html editor!

Important Note:  You need to try this using "standard web forms". This option can be changed from your profile settings.