Setting a page layout

I have been working on my own theme, and ended up breaking Moodle…  just a little. When viewing my messages (/message/index.php?user1=2&user2=3), I discovered that the layout had gotten out of wack. I somehow had two side-pre columns – one beneath the other.

Long story short I fixed it by doing the following.

  1. First I found out which layout the page was using. – you could use print_object($PAGE->pagelayout)
  2. Then I created a new layout type in the theme config file
  3. Lastly I assigned my new layout to the page.

If you know which layout is being used, you can control what happens on the screen. Below are some code snippets. My changes are in red.

 

Layout code in the page I was changing
if (substr($viewing, 0, 7) == MESSAGE_VIEW_COURSE) {
    $courseid = intval(substr($viewing, 7));
    require_login($courseid);
    require_capability('moodle/course:viewparticipants', context_course::instance($courseid));
    $PAGE->set_pagelayout('incourse');
} else {
    //$PAGE->set_pagelayout('course');
    $PAGE->set_pagelayout('incourse');
    $PAGE->set_context(context_user::instance($user1->id));
}

My new layout in the theme->config.php file
$THEME->layouts = array(
 // Front page.
 'frontpage' => array(
 'file' => 'frontpage.php',
 'regions' => array('side-pre', 'side-post'),
 'defaultregion' => 'side-pre',
 'options' => array('langmenu'=>true),
 ),
 // Main course page.
 'course' => array(
 'file' => 'course.php',
 'regions' => array('side-pre', 'side-post'),
 'defaultregion' => 'side-pre',
 ),
 //
 'base' => array(
 'file' => 'columns3.php',
 'regions' => array('side-pre', 'side-post'),
 'defaultregion' => 'side-pre',
 ),
 'base' => array(
 'file' => 'columns3.php',
 'regions' => array('side-pre', 'side-post'),
 'defaultregion' => 'side-pre',
 ),

 'incourse' => array(
 'file' => 'columns3.php',
 'regions' => array('side-pre', 'side-post'),
 'defaultregion' => 'side-pre',
 ),
 
);

Leave a Reply

Your email address will not be published. Required fields are marked *