How to add a block to the center of a page in Moodle?

雨燕双飞 提交于 2019-12-06 12:41:48

问题


I wanted to display a comment block below the activity rather than on the left or right side bars.

It was a lot easier than I thought.

I've added code for center-post which will add a block at the bottom of the main content. It could easily be modified to have a centre-pre for displaying at the top of the main content.


回答1:


In /theme/yourthemename/config.php

Add 'centre-post' to the regions() array for each page layout where it is required. Eg for modules only added it to 'incourse' layout

 // Part of course, typical for modules - default page layout if $cm specifi
 'incourse' => array(
     'file' => 'general.php',
     'regions' => array('side-pre', 'side-post', 'center-post'),
     'defaultregion' => 'side-pre',
 ),

In /theme/yourthemename/lang/en/theme_yourthemename.php add

$string['region-center-post'] = 'Center Bottom';

In /theme/yourthemename/layout/general.php

near the top after $hassidepost ... add

$hascenterpost = (empty($PAGE->layout_options['noblocks']) && $PAGE->blocks->region_has_content('center-post', $OUTPUT));

then look for MAIN_CONTENT_TOKEN and add

<div class="region-content"> <?php echo core_renderer::MAIN_CONTENT_TOKEN ?> </div>
// Add this
<?php if ($hascenterpost) { ?>
<div id="region-center-post" class="block-region">
<div class="region-content">
<?php echo $OUTPUT->blocks_for_region('center-post'); ?>
</div>
</div>
<?php } ?>
// End of add this
<?php echo $coursecontentfooter; ?>

Now go to a module, add a block to the module and you will have a choice to move the block to the centre bottom.



来源:https://stackoverflow.com/questions/23741955/how-to-add-a-block-to-the-center-of-a-page-in-moodle

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!