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();
?>

3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete