Avindra Goolcharan
Avindra Goolcharan

Reputation: 4211

Permanently show block in Moodle?

Is there a way to permanently show a block within Moodle? I am working on configuring a theme, and I wanted to know if there's a way to ensure that a block is visible no matter which page you're on.

Upvotes: 1

Views: 336

Answers (1)

benomite
benomite

Reputation: 868

One solution should be to add a new block region.
In your theme directory, in config.php file, modify the layout option and add your new region to all your used layouts:

$THEME->layouts = array(
'base' => array(
    'file' => 'admin.php',
    'regions' => array('your-region'),
    'defaultregion' => 'your-region',
),
'standard' => array(
    'file' => 'admin.php',
    'regions' => array('your-region', 'side-post'),
    'defaultregion' => 'your-region',
),
// The site home page.
'frontpage' => array(
    'file' => 'general.php',
    'regions' => array('tools-menu', 'side-post'),
    'defaultregion' => 'tools-menu',
    'defaultregion' => 'tools-menu',
),
'course' => array(
    'file' => 'general.php',
    'regions' => array('your-region'),
    'defaultregion' => 'your-region',
    'options' => array('nofooter'=>true, 'nonavbar'=>true, 'nocustommenu'=>true),
),
etc...

Then you edit all your layout files theme/your_theme/layout/*.php and add this line where you want your block to appear:

echo $OUTPUT->blocks_for_region('your-region');

Now, you will have to add your block to this region for all page type, simply execute this sql in you database:

INSERT INTO `mdl_block_instances` (
`id` ,
`blockname` ,
`parentcontextid` ,
`showinsubcontexts` ,
`pagetypepattern` ,
`subpagepattern` ,
`defaultregion` ,
`defaultweight` ,
`configdata`
)
VALUES ( NULL ,  'your_block_name',  '1',  '1',  '*',  NULL,  'your-region',  '0', NULL );

Upvotes: 1

Related Questions