Moving blocks to the center of the page in moodle's front page

Moving blocks to the center of the page in moodle's front page

Di Juwel tomonidan -
Number of replies: 54

Hi

in the front page of moodle:
is there a way to position a block in the center of the page instead of the left or the right ?

O'rtacha reytinglar:Useful (2)
In reply to Di Juwel

Re: Moving blocks to the center of the page in moodle's front page

franziss franziss tomonidan -

I need to know this too! Can someone help us out? Thanks alot!

In reply to franziss franziss

Re: Moving blocks to the center of the page in moodle's front page

Mary Cooch tomonidan -
Documentation writers rasmi Moodle HQ rasmi Particularly helpful Moodlers rasmi Testers rasmi Translators rasmi

You can't currently move blocks to the centre - however; depending on which block it is you might be able to do a workaround. Which block(s) do you want to move?

In reply to Mary Cooch

Re: Moving blocks to the center of the page in moodle's front page

franziss franziss tomonidan -

I have created my own block, and would like to move it to the center. I have read somewhere that we can move blocks to the center under mymoodle page, but my block is not shown under mymoodle page.

In reply to franziss franziss

Re: Moving blocks to the center of the page in moodle's front page

Paul P. tomonidan -

The only way to have a block in the center (prior to 2.0) is to apply a patch.  There is one here at http://tracker.moodle.org/browse/MDL-6748

In reply to Paul P.

Re: Moving blocks to the center of the page in moodle's front page

franziss franziss tomonidan -

I am currently using moodle 2.0, do I need to aply this patch? Because I can't move my created block to the center of the page

In reply to franziss franziss

Re: Moving blocks to the center of the page in moodle's front page

Mary Cooch tomonidan -
Documentation writers rasmi Moodle HQ rasmi Particularly helpful Moodlers rasmi Testers rasmi Translators rasmi

I can't tell you whether that patch will work with 2.0 as I can't read code but I can tell you that natively the only area in 2.0 where you can move blocks to the centre is the MyMoodle page.

In reply to franziss franziss

Re: Moving blocks to the center of the page in moodle's front page

Tim Hunt tomonidan -
Core developers rasmi Documentation writers rasmi Particularly helpful Moodlers rasmi Peer reviewers rasmi Plugin developers rasmi

The existing patch definitely won't work in Moodle 2.0.

The good news is that the new blocks system in Moodle 2.0 was designed to make this sort of thing very easy to implement.

The bad news is that no-one has actually implemented it.

The good news is that it is really, really, easy to implement. See the attached patch. You only need to add two lines of code to index.php.

(Excuse the smugness, but I am feeling really quite pleased with myself right now. The new Moodle 2.0 blocks system one of my best pieces of work.)

In reply to Tim Hunt

Re: Moving blocks to the center of the page in moodle's front page

Urs Hunkler tomonidan -
Core developers rasmi

I ask you and all developers responsible for the "mymoodle" and the "user profile" page here related to the actual "blocks in the center of the page" question.

When I first saw how the center block region for those two pages in Moodle core are implemented I wondered why the blocks are implemented in this "hacky" way?

We have the layout files for the 'mydashboard' and for 'mypublic' page. From my understanding the definition for the 'content' region belongs in these layout files and not into page code.

The hack to create the region in page code breaks the overall concept and creates disadvantages. One is that the close relation in the theme between the layout files - the page structure - and the CSS - the page formatting - is broken. The other is that the principle that page code delivers the content and theme designers decide following client needs where the blocks are placed via region placement in the layout file is ignored.

A decision and a clear commitment to the Moodle 2.0 rules for developers and theme designers would make much sense and would help to keep the new structure clean and consequently implemented within Moodle. What do you and some of the core developers (Martin, Petr, Sam ...) think?

In reply to Urs Hunkler

Re: Moving blocks to the center of the page in moodle's front page

Tim Hunt tomonidan -
Core developers rasmi Documentation writers rasmi Particularly helpful Moodlers rasmi Peer reviewers rasmi Plugin developers rasmi

I think we can separate two separate things:

There is the core of the blocks system (blocklib.php). Blockslib knows a bit about pages. As far as it is concerned, a page is defined by three things

  1. A context id
  2. A page type (like mod-quiz-view)
  3. and optionally a subpage identifier. This is only needed when you have something like the book modules, where there are a lot of different pages for which 1. and 2. are the same.

blocklib also has a list of what regions on the page blocks can appear in.

That is all the information blocklib need in order to work out which specific block instances appear in which regions on this page.

That is the world as far as blocklib is concerned, and it is quite flexible.

 

Now it is a separate issue "Who tells blocklib which regions are on this page?"

Normally, as you say, it is the theme that declares which region of blocks are on this page in this theme (via the declarations in the theme's config.php).

However, the block system does not care, and any bit of code may call $PAGE->blocks->add_region(...) at any time before the call to $OUTPUT->header().

So, all sorts of things will 'work'. It is really a matter of convention what we choose to do. Just like we have a lot of other conventions in the Moodle world (for example the coding guidelines) to help people do thing the 'right' way.

In a sense, what you are asking is "What is the right convention for who defines which block regions are on the page?" This is a good question to ask.

 

Now, the other thing to consider is that all Moodle pages have a bit of content that goes in the [Main content goes here] place in the layout.php file. That is not how it would work if we were designing the page layout system from scratch, but because Moodle 2.0 was built on Moodle 1.9, this was necessary. Perhaps in Moodle 2.x, for sufficiently large x it will be possible to get rid of that. (It may be possible once all pages in Moodle have been converted to use a renderer to generate what goes in the [Main content goes here] place.)

Now we took the decision that for certain pages, currently 'mydashboard' and 'mypublic', but probably in future the site front page and the course/categories.php page, it would be better not to have any fixed content in in the [Main content goes here] area. Instead, this area would just contain blocks.

Now there are two ways you could do that. One is for the script, that is usually responsible for generating the [Main content goes here], to declare that blocks region, and print the blocks in there.

As you point out, the alternative options is to require that the theme defines an appropriate template for the 'mydashboard' and 'mypublic', which includes the 'content' block region (or whatever your theme wants to call that region).

Both of these solutions will work, on the whole. Which you think is better depends, as I say, on convention. And, as we have seen, changing this convention only involves moving two lines of code from certain pages into the them.

 

However, at this moment in Moodle's evolution, I think there is a strong reason to prefer the first solution, which is what is currently implemented.

As I said, I think it would be a good idea if we got rid of the hard-coded content from the front page, and made this front page like the my Moodle page. The whole [Main content] bit of the page consists of just a block region.

In order to do this, we would need to make some new blocks that display the various things that the admin can currently choose to display on the front page using the front page settings.

Then you would need to write some upgrade code, that looks at the current front-page settings, and add the appropriate blocks to the front page 'content' region to replicate the current set up.

Then you have to actually change the code that prints the front page. And depending on whether it is the main index.php script, or the theme, that controls these blocks that can go two ways.

1. If index.php does add_block_regino('content') and then prints the block in that region, the to convert index.php you just delete the old code that prints the content in [Main content area] and replace it with $OUTPUT->blocks_for_region('content');

2. On the other hand, if you say the theme must be responsible for this, then after you have removed the old code from index.php, you have to update the frontpage template in every standard theme to include the new blocks region. Then, for every admin who is upgrading to this new version of Moodle, and who uses a custom theme, you have to make sure they know to update the frontpage template in their custom theme to include the new blocks region, because if they don't the front-page of their site will break horribly when the do the upgrade, then they will come to the forums and complain, and we will have to help them sort out the mess.

 

So, my view is that at the moment, while we are working to convert Moodle to have less hard-coded content in certain scripts, and to take a more flexible approach to layout, it is better to allow ourselves option 1.

It may not be the purest and most idealistic interpretation of the way the blocks system is meant to work, but for now it is practical, and makes it easier for us to continue to move in the right direction.

However, that is just my current thinking. Given suitable arguments, I could be persuaded to change my mind.

In reply to Tim Hunt

Re: Moving blocks to the center of the page in moodle's front page

Urs Hunkler tomonidan -
Core developers rasmi

Thank you Tim for your detailed explanation.

You talk about developer conventions and how the code is created. I talk about the end user and their needs. In the world of visual communication the way the page looks and feels is important. A system delivering pages needs to be as flexible as possible to make customizations for special needs easy. With customizations I don't think of primarily PHP development but more of HTML/CSS work.

With Moodle 2 the layout files are used to create the pages. One important advantage is that these layout files offer the flexibility to customize the pages towards clients/users needs. Each place in Moodle where a developer defines the page layout is a lost place for the designer to customize the page.

Now two arguments to prefer and even encourage the usage of the layout files to define regions

  • Block regions added by code are contra productive and are a bad thing from the page layout flexibility point of view.
  • In a change process the new way of doing something is much faster understood and accepted when you offer as little fallbacks to the old thinking as possible. In the blocks case when developers are asking for ways how to implement blocks on a certain area of the page the new structure is faster accepted when you answer "Create a region in layout and put your blocks there" and don't offer fallbacks with "Create a region in code".

And a question

  • What would you tell a developer who asks how to place blocks in the header area?

By the way - with the start of Moodle 2 I stopped thinking about Moodle 2 pages as header - 3-column and content only in the middle - footer. For me Moodle pages are open to communicative/design needs. There is still a content area - but it really does not need to be in the middle column. It can be anywhere on the page where it makes sense. And in several areas Moodle supports this thinking.

And the more I think/write about this responsibility/convention question the more I notice how important it is to work for a clear understanding of the advantage of page structure flexibility for learners and trainers. For these persons the learning environment is built. There are many different needs, cultural differences, personal preferences on the client side for each learning environment. The system with the most flexibility to follow these demands will be the best solution to support learning in a convenient way.

Looking at the plethora of developer created patches, blocks, modules etc. one sees how many demand there is for custom solutions. Better would be developers handle content creation and designers handle content presentation based on a flexible system - both according to their main skills.

Basically separating content from presentation is the goal. In Moodle 2.0 a first important step in this direction has been made. I propose to support and encourage all people to use the new ways - developers, designers and users. And to offer as little fallbacks, backdoors or similar to the pre Moodle 2.0 ways.

I would really like to hear from Martin, Petr and/or other core developers how they think about this topic.

In reply to Urs Hunkler

Re: Moving blocks to the center of the page in moodle's front page

Tim Hunt tomonidan -
Core developers rasmi Documentation writers rasmi Particularly helpful Moodlers rasmi Peer reviewers rasmi Plugin developers rasmi

When you say "With customizations I don't think of primarily PHP development but more of HTML/CSS work." I think you are only considering two levels of customisation. I prefer to think of three:

  1. What the administrator can do. Installing different plugins and themes, and changing configuration settings.
  2. What you can do with HTML/CSS (that is make a new theme) and perhaps simple PHP skills (for example, make a new block that displays some particular information just the way you want, or tweak a renderer in your theme.)
  3. What you can only change by serious PHP hacking of the core Moodle code, or by making a major new plugin.

2. and 3. here are meant to correspond to your two options, but I have re-expressed them in my own words.

I think that any time we move something to a smaller number is progress. Moodle 2.0 moved quite a lot of page layout from 3. to 2. which was good. Something like the change to My Moodle moves some things from 3. to 1., which I think is even better.

 

I think that changing the site front page so that it no longer uses fixed hard-coded content, but instead is made up of whatever blocks the admin wants to add there, is a really huge step forwards in the 1. area. (And in the 2. area, because then people can display custom output on the front page just by making a new block.)

Therefore, I think that achieving this by whatever means is definitely a good thing that should be done, and that the decision about whether to make the change at level 2. or level 3 is a secondary debate. In this case, making this change at level 3. requires 2 lines of code, but making the change at level 2. requires changing every theme. So, in this case, my approach would be to add the two lines of code to index.php, but I am not volunteering to do the work on this, and if someone else chooses to implement it another way, I would not object.

 

I will raise one other point. Suppose you have a site that is set up so that users can choose their own theme. And suppose that we have gone down the road you recommend, where different themes can choose which block regions appear on the front page. Can you be sure that as user switch between different themes, that the front page continues to look OK?

As long as index.php does add_block_region('content') then the front page is more likely to continue to work well in all themes. I don't think this is a very strong point, but it is worth considering.

 

P.S. To answer your question, if someone developing a particular Moodle script, say a new Activity module, asks how to put blocks in the header, they I would definitely say "That is none of your business, that is up to the theme."

In fact, I suspect I have already said that somewhere, although not in that form. The more common question is "I don't want these blocks appearing on my page. I want all the space for my wonderful [Main content]." The answer is still the same though: "That is none of your business, developer, that decision is up to the theme."

 

I doubt if Martin/Petr/Sam read this forum normally, I will point them in this direction.

In reply to Tim Hunt

Re: Moving blocks to the center of the page in moodle's front page

Urs Hunkler tomonidan -
Core developers rasmi

With Moodle 2.0 blocks I have been working more intensive lately and I love how flexible and solid the block implementation works.

Overriding renderers, creating new block types to present content in different and special ways is relatively easy and just works. No surprises so far.

We can think about presenting Moodle content on the pages quite different in 2.0 and create pages needed or demanded from clients a lot more flexible and much closer to their needs.

Some examples will be shown in the near future on moodle.de.

In reply to Tim Hunt

Re: Moving blocks to the center of the page in moodle's front page

Helmut Irle tomonidan -

Hi Tim,

Regarding your patch - that's great news, but it's not yet working for me. Was there anything else I needed to do that was implied but not mentioned? I added the two lines to index.php, but do not see any difference to the front-page. I can't add any blocks to the center/content region. Are any other changes required - maybe to my theme?

After applying your patch, what should the result be?

I would appreciate any help. Tabassum

Thanks!

Helmut

In reply to Helmut Irle

Re: Moving blocks to the center of the page in moodle's front page

Helmut Irle tomonidan -

I've now tried the theme route, and that seems to work well, so far. Finally making some progress... Tabassum

In reply to Helmut Irle

Re: Moving blocks to the center of the page in moodle's front page

Tim Hunt tomonidan -
Core developers rasmi Documentation writers rasmi Particularly helpful Moodlers rasmi Peer reviewers rasmi Plugin developers rasmi

I don't think there was anything else you needed to do other than to add those two lines, but if you got this working in your theme, that is probably better.

In reply to Tim Hunt

Re: Moving blocks to the center of the page in moodle's front page

Daniel Munera tomonidan -

Indeed it was really easy to implement, I am using the main-content region inside the layout of my theme and it is working fine. Thanks a lot.

In reply to Daniel Munera

Re: Moving blocks to the center of the page in moodle's front page

Phillip McAbee tomonidan -

Hi Daniel,

I need to do the same thing - I'm trying to move the HTML block to center page but I'm having no luck - any help would be appreciated - Thanks


I'm using Moodle 2.7

In reply to franziss franziss

Re: Moving blocks to the center of the page in moodle's front page

Urs Hunkler tomonidan -
Core developers rasmi

Tim described the solution from a developer point of view. Tim's example creates a hack. But when you read the Moodle documentation you will learn that it is strongly recommended not to hack core files.

With Moodle 2.0 we have a non hacking way to place blocks on Moodle pages in the middle page area of the front page or many other pages. In the theme you add 'content' to the regions for the frontage in the theme config.php. Then in the layout file "frontpage.php" you check for blocks in that region and ´echo $OUTPUT->blocks_for_region('content')´ in the same manner as it's done for the other regions on that page. Easy too and no hacks needed - no problems with updates etc.

And to go the "official" way in the themes has the big advantage that the change is close to all the CSS you might also add to make the block look good in the content area. The area is wider than the side columns, you may want the header to display different, you may want to hide the buttons for docking and the "minus" icon for collapsing the content etc. All these changes make more sense in the theme than in any other place.

In reply to Urs Hunkler

Re: Moving blocks to the center of the page in moodle's front page

franziss franziss tomonidan -

Thank you for your instructions, I have a block questionAnswer.

I tried to following your instructions, in the theme file config.php, I added

$THEME->layouts = array(

'question' => array(
'file' => '../blocks/questionAnswer/block_questionAnswer.php',
//'file' => 'block_questionAnswer.php',
'regions' => array('question'),
'defaultregion' => 'question'

)

And then in file frontpage.php,

I added <?php echo $OUTPUT->blocks_for_region('question') ?>

But now the moodle page states that there is error. Where did I go wrong? Thank you for your kind help.

 

In reply to franziss franziss

Re: Moving blocks to the center of the page in moodle's front page

Urs Hunkler tomonidan -
Core developers rasmi

Please read the theme documentation in Moodle docs for the details.

In short you change the frontpage so you need to extend the frontpage definition in config.php by adding the 'question' region there. Then Moodle knows about the new region on the frontpage and you can output the 'question-region' blocks in frontpage.php. When I understand your code example right you add a new page type.

In reply to Urs Hunkler

Re: Moving blocks to the center of the page in moodle's front page

Jeroen Vi tomonidan -

Thanks Urs, for describing the non-hacking way of placing a block in the middle of a page.

 

In reply to Jeroen Vi

Re: Moving blocks to the center of the page in moodle's front page

Paul P. tomonidan -

For all interested, here is what I have done to implement center blocks in moodle 2.  And Tim, you have every right to be smug - the implementation was easy, and only modified a few theme files.

I chose to modify the "base" theme, which will impact the 'standard theme', however, the principal should work in any theme.

1.  Open config.php and find the $THEME->layouts array.  Find all instances of the line 'regions' => array('side-pre', 'side-post'), and add another region or two.  I added two, as follows: 'regions' => array('side-pre', 'side-post', 'center-pre', 'center-post'),. I edited them in 'standard', 'course', 'coursecategory', 'incourse', 'frontpage', 'mydashboard' and 'mypublic'.

2.  In the directory 'layout', edit the files 'frontpage.php' and 'general.php'. In each, I made the following changes:

a) Near the top, just after the first 4 $hassidepre, etc declarations, add

in 'frontpage.php' add
$hascenterpre = $PAGE->blocks->region_has_content('center-pre', $OUTPUT);
$hascenterpost = $PAGE->blocks->region_has_content('center-post', $OUTPUT);

in 'general.php' add
$hascenterpre = (empty($PAGE->layout_options['noblocks']) && $PAGE->blocks->region_has_content('center-pre', $OUTPUT));
$hascenterpost = (empty($PAGE->layout_options['noblocks']) && $PAGE->blocks->region_has_content('center-post', $OUTPUT));

The remaining changes apply to both 'frontpage.php' and 'general.php'
$showcenterpre = $hassidepre && !$PAGE->blocks->region_completely_docked('center-pre', $OUTPUT);
$showcenterpost = $hassidepost && !$PAGE->blocks->region_completely_docked('center-post', $OUTPUT);

b) before the if($hascustommenu) section, add
if ($hascenterpre) {
    $bodyclasses[] = 'has_center_pre';
}
if ($hascenterpost) {
    $bodyclasses[] = 'has_center_post';
}

c)  Between the  <div id="region-main-wrap"> and <div id="region-main"> lines add

                <?php if ($hascenterpre) { ?>
                <div id="region-center-pre" class="block-region">
                    <div class="region-content">
                        <?php echo $OUTPUT->blocks_for_region('center-pre') ?>
                    </div>
                </div>
                <?php } ?>

and between their two respective </div> tags add

                <?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 } ?>

3. Next, in the 'style' directory, open pagelayout.css, and add the following:

#page-content #region-center-pre, #page-content #region-center-post {margin-right:0px;margin-left:400px;overflow:hidden;}

4.  Finally, in the 'lang/en' directory, add the following lines to 'theme_base.php':

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

Thus, you now will have a region for blocks both above and below the main section in both the frontpage and course pages.  I haven't tested it fully, but it looks like it is working.

I hope this helps someone, and any feedback will be appreciated.

In reply to Paul P.

Re: Moving blocks to the center of the page in moodle's front page

Mary Evans tomonidan -
Core developers rasmi Documentation writers rasmi Peer reviewers rasmi Plugin developers rasmi Testers rasmi

Hi,

Why did you not test this fully first, as it might not work as you expect! Tabassum

Can it be docked? I know Base does not have docking blocks set, so you wont know this, but if someone added this into another theme, there may be conficts, especially with page layouts.

There is/or was a Course Format that added extra blocks in a course page, the only problem was that you need to declare the $strings in the theme, and as the $strings were in the course format lang directory it wasn't the success it should have been.

Cheers

Mary

In reply to Mary Evans

Re: Moving blocks to the center of the page in moodle's front page

Paul P. tomonidan -

In programming, can anything ever be truly fully tested?  If that were possible, bug fixes wouldn't be necessary Miltillatmoq

As I stated in my post, this is specific to the "base" theme, which in turn allows the "standard" theme to enjoy the two center block regions I set up.  I'm sure that in other themes, there would be other considerations, but when creating a new theme, the "standard" theme is the best place to start, or so that's what I gathered from the discussions.  I haven't tried it in other themes, but the theme engine is very straightforward (kudos to Tim!) and I think that with similar edits, it should work just as well (key word being "think").  I think the only problem in other themes is that the frontpage.php and general.php layout of the base theme are overridden by their own layouts.

In the standard theme, at least, docking works, and inserting modules and resources works.  Blocks can be moved around in their respective sections.  I tested "Latest News", "Upcoming events" and "Search forums".  I inserted a "Database" module in a course section and then proceeded to successfully move the module as well as the course sections around without difficulty.  The only odd thing is that when I tested an "HTML block" and a "Calendar block", it seemed to mix up the "top center" and "bottom center" regions when I tried to set them in the "configure block" screen, but that is probably me mixing the two up somewhere (interestingly, the other blocks set to the be in the center section defaulted to the left side in the configuration screen but returned to their center positions upon saving).  If you want to see it, go to http://www.webfored.com/m2/course/view.php?id=2 - it's just a test installation and that's the only course, currently.

Regarding the strings, they seem to work as expected, showing up in the "Region" sections on the HTML and Calendar blocks, so I'm not sure what the issue was you were referring to.  If you give me some more information, I can see if it is an issue with this modification.

I posted this for informational reasons only, hoping others in the community would try it out and report their findings.  I have used center blocks extensively in the various 1.9 installations that I manage and many, many teachers like putting blocks in the center as well.  As I start the move to moodle 2, the first thing that I have to ensure is that this feature will work.

Anyway, thanks for your thoughts on this, and if you get a chance to try it out, let me know what you find.

In reply to Paul P.

Re: Moving blocks to the center of the page in moodle's front page

Mary Evans tomonidan -
Core developers rasmi Documentation writers rasmi Peer reviewers rasmi Plugin developers rasmi Testers rasmi

Hi,

Last year I was helping solve some problems with blocks in the Aardvark 2.1 and ended up making my own version of this theme and calling it Aardvark Post-IT and adding 2 block regions into a hidden section of the header which is toggled show/hide using javascript.

It was a big learning curve...but very rewarding.  The problems I ran into were that in the first instance I made the name of my blocks too long by one letter.  The second problem was that I forgot to add the strings in the lang/en/aardvark_postit.php. There last problem I had was when docking all the blocks apart from the ones in the hidden area. These hidden blocks casued the page to retain the layout of a 3 column page where the 2 side columns were empty. The reason for this was the class selector I used was "block-region" which I have since dispenced with and the whole things work fine now.

The problem I mention in my earlier comment was related to the course format which added about 6 blocks to a course page. The problem is it did not work unless you added the strings from the course format into your theme.

Thanks for the link I'll take a look see what you have done.

Cheers

Mary

In reply to Paul P.

Re: Moving blocks to the center of the page in moodle's front page

Sheila Stamp tomonidan -

Hi Paul This was a huge help - thank you.  It worked a treat and to go full circle, Mary, I have implemented it into our adaptation of Aardvark Post-IT.

The only thing is that I got mighty confused when testing as the top block kept appearing in the bottom and vice versa.  

I then spotted that you had:

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

which should be the other way around.  Hope that helps anyone else who implements this.

I also moved the post centre region to just above the footer (after the main content) which suits our purposes better.  Still testing it out and will let you know if I find anything else.

Thanks again!

Sheila

In reply to Sheila Stamp

Re: Moving blocks to the center of the page in moodle's front page

Mary Evans tomonidan -
Core developers rasmi Documentation writers rasmi Peer reviewers rasmi Plugin developers rasmi Testers rasmi

Hi Shiela,

First of all I would put the outputs for the two blocks one above the main output for the page and the other below it like so...

<div id="region-main-wrap">
<div id="region-main">
<div class="region-content">
<div id="mainpadder">

<?php if ($hascenterpre) { ?>
<div id="region-center-pre" class="block-region">
<div class="region-content">
<?php echo $OUTPUT->blocks_for_region('center-pre') ?>
</div>
</div>
<?php } ?>

<?php echo $OUTPUT->main_content() ?>

<?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 } ?>
</div>
</div>
</div>
</div>

HTH

Mary

In reply to Mary Evans

Re: Moving blocks to the center of the page in moodle's front page

Rachel Fransen tomonidan -

I don't know if I did something really wrong in my CSS file, but:

-- I've added a center block on my course view.

-- But if I dock all the other blocks, the center block makes my section topics also centered in the page, with about 15% whitespace on left/right margins

How can I make my center blocks look like the frontpage, where the centerblock AND the content expands the width of the whole page?

In reply to Rachel Fransen

Re: Moving blocks to the center of the page in moodle's front page

Paul P. tomonidan -

On my test page, neither the content nor the center blocks expand to the entire page, so I am assuming it is a css issue.

Without seeing your page, it's hard to tell what is happening.

Did you try setting a maxwidth?  Perhaps that would help.

In reply to Paul P.

Re: Moving blocks to the center of the page in moodle's front page

Rachel Fransen tomonidan -

It only expands to the entire page on the "frontpage" of moodle. Inside my "course" page, everything is shoved to the center of the page.  Again, this only occurs if all other blocks are docked EXCEPT my center block

It's strange though....when the page loads, it is 100% width. But then when the page finishes loading, everything gets centered. So there has to be a code somewhere that is saying: "region-post" or "region-pre" is still taking up space on the page. 

See the screenshot:

In reply to Sheila Stamp

Re: Moving blocks to the center of the page in moodle's front page

Paul P. tomonidan -

Good catch, Sheila.  I sometimes get my "rights" and "lefts" mixed up as well.  You can imagine how much it infuriates a driver when I'm giving directions Tabassum

In reply to Paul P.

Re: Moving blocks to the center of the page in moodle's front page

Sheila Stamp tomonidan -

Hi Paul

The blocks in the centre have been working a treat until I tried to add a group in a test course and got an exception from blocklib.php:

Coding error detected, it must be fixed by a programmer: Trying to reference an unknown block region center-pre

I am extremely loathe to change base code outside the theme - do you or Mary have any ideas as to how to get around this little dilemma?

The stack trace is:

ine 857 of /lib/blocklib.php: coding_exception thrown
line 959 of /lib/blocklib.php: call to block_manager->check_region_is_known()
line 972 of /lib/blocklib.php: call to block_manager->ensure_instances_exist()
line 458 of /lib/blocklib.php: call to block_manager->ensure_content_created()
line 26 of /theme/aardvark_dbis/layout/general.php: call to block_manager->region_completely_docked()
line 685 of /lib/outputrenderers.php: call to include()
line 637 of /lib/outputrenderers.php: call to core_renderer->render_page_layout()
line ? of unknownfile: call to core_renderer->header()
line 1363 of /lib/setuplib.php: call to call_user_func_array()
line 137 of /group/index.php: call to bootstrap_renderer->__call()
line 137 of /group/index.php: call to bootstrap_renderer->header()

Many thanks!

All the best

Sheila

P.S. Mary thanks for the positioning suggestions - much appreciated.

 

 


 

In reply to Sheila Stamp

Re: Moving blocks to the center of the page in moodle's front page

Sheila Stamp tomonidan -

Hi Paul

I fixed it.  I needed to add

'standard' => array(
'file' => 'general.php',
'regions' => array('side-pre', 'side-post', 'pbar-pre','pbar-post', 'center-pre', 'center-post'),
'defaultregion' => 'side-post',
),

to the config.php.  The aardvark post it theme didn't have it.

All working now!

Thanks

Sheila

In reply to Sheila Stamp

Re: Moving blocks to the center of the page in moodle's front page

Paul P. tomonidan -

Apologies for the late reply - I haven't had a chance to check this forum in a bit, but I'm glad you got it working.  Different themes have different regions defined, so you may have to add regions to get it to work.

In reply to Paul P.

Re: Moving blocks to the center of the page in moodle's front page

Jeff Ferrell tomonidan -

Has anyone experimented with this in the Clean theme in Moodle 2.5?

a) There's no frontpage.php file in the BootstrapBase, so I'm not sure where to put the 

$hascenterpre = $PAGE->blocks->region_has_content('center-pre', $OUTPUT);
$hascenterpost = $PAGE->blocks->region_has_content('center-post', $OUTPUT);

declarations, or if they're needed. The others, I put in general.php.

 

b) The $hascustommenu section looked different in this theme, as well, so I put these $bodyclasses[] declarations after the line $bodyclasses[] = $layout; Don't know if this is correct or not, but if I load the Moodle page, the <body> section does have the classes has_center_pre and has_center_post, so I assume that's working?

c) There's no <div id="region-main-wrap"> and <div id="region-main"> in BootstrapBase, either, so I tried putting the if($hascenterpre) and $hascenterpost display code blocks around <?php echo $OUTPUT->main_content() ?>, which seemed logical...

The rest seems to be working ok—I have the option to choose Bottom Center and Top Center for the blocks. But they don't actually display in the center, nor can I spot the appropriate divs. 

Anybody have an idea what I'm overlooking?

 

In reply to Paul P.

Re: Moving blocks to the center of the page in moodle's front page

Paul Rettey tomonidan -

Hi Paul,

Thanks very much for the useful code, I've managed to get it working in the base theme. However when I unset the theme it does produce and error.

I'm a bit of newbie when it comes to php so I can only assume getting it working in the base theme is a good thing but when unsetting the theme it has this problem.

"Coding error detected it must be fixed by a programmer. Trying to reference and unknown block region center pre"

**Edit: Sorry I should give details of how the error comes up. Ok it does work when the theme is not set the only problem is that when I want to edit the front page settings the error then throws and then I have a an issue that I can't do anything due the error. However If I don't turn editing on it seems to behave itself.

The thing is when Base is selected as theme it works fine, when it isn't selected it throws this error.

Any assistance from anyone would be good!

oops, yes we're on Moodle 2.3.8

In reply to Paul Rettey

Re: Moving blocks to the center of the page in moodle's front page

Paul Rettey tomonidan -

I know I'm replying to my own post but after further testing its worth noting that I couldn't 'unset' a theme. So I'll try to add some clarity to my ramblings:

Added the code Paul produced to Base

Applied the base theme and I was able to add a block to the middle

Changed the theme to standard

Seemed to work ok until I was able to edit the page, and move a block to the middle. However when  I went to apply it the error came up:

"Coding error detected it must be fixed by a programmer. Trying to reference and unknown block region center pre"

Any ideas?

 

In reply to Urs Hunkler

Re: Moving blocks to the center of the page in moodle's front page

Paul Kandzia tomonidan -

Hello,

thanks to this most helpful forum discussion I managed to place a block in the center of the frontpage. However, there ist still a problem:

If the region definition is added in the config.php, as

'frontpage' => array(
        'file' => 'frontpage.php',
        'regions' => array('side-pre', 'center', 'side-post'), 
        'defaultregion' => 'side-pre',
    ),

as effect, in the region settings of any block, the option region-center is shown, regardless of the context of the block. I would expect the option "region-center" only in the frontpage context, as defined, however every teacher will find it on his / her coursepage etc. Of course, using the option there will lead to errors, since I define a layout only for the frontpage (I intend to use the plugin block course_overview_campus exclusively on the frontpage replacing the standard courses/categories combo list. We are using Moodle 2.4.3).

Do I get something wrong?

Thanks in advance,

Paul

In reply to Di Juwel

Re: Moving blocks to the center of the page in moodle's front page

Gus Hagelberg tomonidan -

I assume I'm not the first to have noticed this, but since Moodle 2.3 you can easily move a block to the center by simply dragging it to the center (turn on editing, click move-button in the block header and move the block to the center.) After that the region "center" appears in the blocks settings.

In reply to Gus Hagelberg

Re: Moving blocks to the center of the page in moodle's front page

Gus Hagelberg tomonidan -

Now I have to qualify this statement. I just realized that this method doesn't help in creating "sticky" blocks.

I want a particular block to be in the center region of myMoodle for all users. If I add the block to myMoodle as an admin and then drag it to the center the "Original block location" in the block settings says "User: Hagelberg Gus". This is not really kosher, I guess. It should be "System".

It seems, however, that the block "Course overview" also has the user as the "Original block location".

In reply to Gus Hagelberg

Re: Moving blocks to the center of the page in moodle's front page

Ray Lawrence tomonidan -

You can set a default My Home page layout see Site admin > appearance. Users can remove it though.

In reply to Gus Hagelberg

Re: Moving blocks to the center of the page in moodle's front page

Samuli Karevaara tomonidan -

I can't get it to work. Is this theme specific, or is there a setting for this somewhere? I'm using 2.3.1, standard theme, tried also with the Arialist theme. Tested Chrome, FF and IE, latest versions.

In reply to Samuli Karevaara

Re: Moving blocks to the center of the page in moodle's front page

Via Internet tomonidan -

Did you get this to work eventually? I'm searching for a solution and can't get it to work in version 2.3.2.

In reply to Via Internet

Re: Moving blocks to the center of the page in moodle's front page

Rosario Carcò tomonidan -

Any output you generate for the center part on the FrontPage should perhaps not be considered to be a BLOCK. I have code that works fine in Moodle 1.9 from Kevin Treussier who implemented a site navigation like I did later on. You can see it here in the center:

https://moodle.test.fhnw.ch/moodleTest/

I think this could be ported also to Moodle 2.x

Rosario

In reply to Di Juwel

Re: Moving blocks to the center of the page in moodle's front page

Jose Mopa tomonidan -

This trick worked for me in Moodle 2.5:

-In frontpage activate edit mode

-Everytime the page refresh, all blocks show for only 2 seconds the icon for move the block (at left of the icon edit block).

-This icon is hidden automatically very quickly, but if you are fast, can click the icon an move the block.

In reply to Jose Mopa

Re: Moving blocks to the center of the page in moodle's front page

Piyush Pandey tomonidan -

I have achieved the same in 2.2 by tweeking into theme

we have used theme Darkb

inside layout->general.php add line after $hassidepost on top of the page

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

 

 

then find for line "<!-- start OF moodle CONTENT -->"

Add  replace the existing div of mainpadder with below code

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

 

in the last edit lang file inside the theme folder and add below code

 

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

 

thats it..

 

If need any more information please do let me know

 

 

 

Piyush

 

In reply to Piyush Pandey

Re: Moving blocks to the center of the page in moodle's front page

Keith Murray tomonidan -

Anybody know if this works in 2.5 or 2.6?  Desperate to replace the misreporting course overview block at my home.  Thanks!

In reply to Keith Murray

Re: Moving blocks to the center of the page in moodle's front page

Fanny Passeport tomonidan -

Hi,

I am also wondering how to move the Calendar block to the center of the front page on 2.6...

Thanks

 

Fanny

In reply to Fanny Passeport

Re: Moving blocks to the center of the page in moodle's front page

Daniel Munera tomonidan -

Hi Fanny,

You can take a look to my moodle theme: https://moodle.org/plugins/view.php?plugin=theme_archaius, it allow you to put block in the center of the page, before and after the main content.

If you want to implement it in another theme let me know and I can help you.

Daniel.

In reply to Daniel Munera

Re: Moving blocks to the center of the page in moodle's front page

Fanny Passeport tomonidan -

Dear Daniel,

 

Thanks a lot for your help! For now, Archaius will probably be what I need. 

 

I will probably see you in other conversations as I will be asking many questions ... Tabassum

 

Cheers,

 

Fanny

In reply to Daniel Munera

Re: Moving blocks to the center of the page in moodle's front page

lital l tomonidan -

Hi daniel,


Can you help me to implement it in the clean theme please?


Thanks,

Lital


In reply to Di Juwel

Re: Moving blocks to the center of the page in moodle's front page

julie prescott tomonidan -

Hi, I know this is a really old thread but I just wanted to post a work-around I have just implemented. 

I am running v2.7.2 and want to move a html block to the centre of my frontpage to display an embedded video from youtube. I was able to mimmick a block by using a label resource added to the center of my page. My label html code is attached.

I know its not ideal but it works! ;)