hdomos
hdomos

Reputation: 1209

Moodle: how do I set default blocks into custom region in new courses?

I have a Moodle site with custom regions, namely 'top' and 'bottom'. I would like to automatically add an HTML block to all new courses in the top region.

I have these in my config.php, and the block is added to the new courses, but in the wrong place, to side-pre region... How can I change this to add the block to the top region?

'course' => array(
    'file' => 'course.php',
    'regions' => array('side-pre', 'top', 'bottom'),
    'defaultregion' => 'bottom',
    'options' => array('nonavbar'=>false),

$CFG->defaultblocks_override = 'html';
$CFG->defaultblocks_site = 'html';
$CFG->defaultblocks_social = 'html';
$CFG->defaultblocks_topics = 'html';
$CFG->defaultblocks_weeks = 'html';

Upvotes: 1

Views: 3231

Answers (1)

franzlorenzon
franzlorenzon

Reputation: 5943

Citing from the docs (Default block layout for new courses):

$CFG->defaultblocks_topics = 'participants,tags,admin:messages,online_users,recent_activity';

Note how the colon is used to separate those blocks appearing on the left, from those appearing on the right.

It seems like you would have to use a colon. I looked at the function code, that parses this string (in lib/blocklib.php, function blocks_parse_default_blocks_list, Moodle 2.4) and I think it could only handle left or right regions (side-pre and side-post). For an hackish solution, you could change this lines of code (in lib/blocklib.php):

define('BLOCK_POS_LEFT',  'side-pre');

To:

define('BLOCK_POS_LEFT',  'top');

But I think a better solution is the use of "sticky" blocks (Moodle > 2.3 required). Have a look at this doc. Here are the different steps:

  1. Add the block in the front page;
  2. Edit the configuration of the block. On the section Where this block appears select Display throughout the entire site;
  3. Select default region, as desired (in your case, top or bottom).
  4. Now you have to show the block only on courses. Enter a course. Edit the block (in the course) and on Display on page types select Any course page.

Now the blocks will appear only on course pages (and not on the front page).

Credits: Re: Block in all Courses in Moodle 2.0. I personally tested it on a Moodle 2.4 installation.

Upvotes: 1

Related Questions