Moodle block ordering

Moodle has many ways to set the order of blocks on the page.

The easiest way is through the default weight variable



There are other ways to set this, one is through the


variable which appears in the config.php

Recently I had to change the order of a block and found that changing the display order through the block admin tool just didn’t work at all. After some searching, I found that it had been set in the theme in theme/<mytheme>/renderers/core_renderer.php

/** * Gets the blocks for the side region * @param $region * @return string * @throws coding_exception */public function blocks_for_side_pre($region) { $blockcontents = $this->page->blocks->get_content_for_region($region, $this); //Sort the blocks in defined order by closure variable $titles usort($blockcontents, function ($a_block, $b_block) { $titles = array('Block 1', 'Block 2', 'Block 3', 'Administration','Another block'); $a = array_search($a_block->title, $titles); $b = array_search($b_block->title, $titles); if(is_numeric($a) && is_numeric($b)){ if($a > $b) { return 1; } else { return -1; 嘉盛 } } return 0; }); $blocks = $this->page->blocks->get_blocks_for_region($region); $lastblock = null; $zones = array(); foreach ($blocks as $block) { $zones[] = $block->title; } $output = ''; foreach ($blockcontents as $bc) { if ($bc instanceof block_contents) { $output .= $this->block($bc, $region); $lastblock = $bc->title; } else if ($bc instanceof block_move_target) { $output .= $this->block_move_target($bc, $zones, $lastblock, $region); } else { throw new coding_exception('Unexpected type of thing (' . get_class($bc) . ') found in list of block contents.'); } } return $output;}

Comments are closed.