Search This Blog

Tuesday, January 31, 2012

How to center blocks inside moodle

I found the answer to this question by googling the Moodle.org forums and tracker, but thought I'd repost this specifically for Moodle 2.1

Original answer can be found here: http://tracker.moodle.org/browse/MDL-6748


1) Go to:  lib/blocklib.php
2) Around line 46, define a new block position:

define('BLOCK_POS_RIGHT', 'side-post');
define('BLOCK_POS_CENTER', 'center');

2) Go to:  theme/[your_theme]/layout/general.php
3) Around line 7, add a new line of code:

$hassidepost = $PAGE->blocks->region_has_content('side-post', $OUTPUT);
$hascenter = $PAGE->blocks->region_has_content('center', $OUTPUT);

4) In the same file, around line 90-96, add a new block of code:

<?php echo core_renderer::MAIN_CONTENT_TOKEN ?>
<?php if ($hascenter) { ?>
   <div class="block-region">
       <div> <?php echo $OUTPUT->blocks_for_region('center') ?></div>
    </div>
<?php } ?>
</div>

5) Go to:    theme/[your_theme]/config.php
6) In whichever page you want to have center blocks, add  'center' to the regions array

'frontpage' => array(
'file' => 'general.php',
'regions' => array('side-pre',
'center', 'side-post'),
'defaultregion' => 'side-post',
),
I did the same thing for:
'course' => array(..... 

Which allowed me to have center blocks within the course pages themselves.
Sweet!

1 comment:

  1. Thank you very much. spent days looking for this.

    ReplyDelete