How do you add a region to a moodle 2.0 theme?

How do you add a region to a moodle 2.0 theme?

by Ben Dunning -
Number of replies: 5

Hi,

Very first post, please be gentle. Especially if I've posted this in the wrong place...

I have read in many threads now, while searching for an answer, that it is possible to create regions anywhere in a moodle 2.0 themes layout.

I'm keen to play with the possibilities that this development offers but despite searching the forums and reading through documentation several times I have yet to find a clear concise description of how to add a region to a layout.

I have no problem with the html or css but i'm very, very limited in php. My attempts at modifying the config.php and a layout.php have not been successful so far: I do not get a new region to move a block too when editing them.

I may have have missed a thread or something obvious in the documentation but I would really appreciate some help. Even if that is to point out the obvious or where this has been discussed elsewhere in depth.

Regards,

Ben

Average of ratings: -
In reply to Ben Dunning

Re: How do you add a region to a moodle 2.0 theme?

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi Ben,

It all depends on what it is you are trying to achive in Moodle 2.0 page layout. Can you expand on your idea of blocks and regions in terms of the final layout envisaged?

Mary

In reply to Mary Evans

Re: How do you add a region to a moodle 2.0 theme?

by Ben Dunning -

Hi Mary,

Thanks for your reply.

I wish to experiment with creating block regions in the header (specifically) and footer parts of a layout, in addition to the left and right (or centre) columns. Also, although not part my original question, I would like to limit the number of blocks that could be moved to the new region. This additional outcome however isn't pressing, just the ability to create new regions.

However your response suggests that creating a new region is not actually as straight forward a process as I had assumed from looking a various resources on moodle.org. My research so far suggested that the basic method for adding a one was for the correct php code to be placed where desired in a layout and the appropriate adjustments made to the config.php.

However checking that I'm adding the right code and making the right adjustments is proving difficult with my very limited php.

Is this enough information?

Thanks again

Ben

In reply to Ben Dunning

Re: How do you add a region to a moodle 2.0 theme?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

It is pretty simple to add a new block region.

I assume you have worked out that a Moodle 2.0 theme has a number of layout templates like http://cvs.moodle.org/moodle/theme/binarius/layout/

Then there is the theme config file like http://cvs.moodle.org/moodle/theme/binarius/config.php?view=markup. The config file lists the various layouts that the theme uses for different types of page, and which block regions each layout has. The example I just linked to mostly just uses side-post as the name of the block region for all layouts.

Then, within the layout file (for example http://cvs.moodle.org/moodle/theme/binarius/layout/general.php?view=markup) you need to call a function to output the blocks in each region, at the point in the layout where you want the blocks to appearl. For example:

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

Obviously, if in config.php, you have said that a certain layout will output blocks in certain regions, then you must live up to that promise in the layout template. You can use whatever wrapper divs you want, I think.

There is no way to enforce a limit on the number of block in a region. (Because of the way sticky blocks work, that would be very hard.) You will just have to rely on teachers being sensible when they set up their course.

In reply to Tim Hunt

Re: How do you add a region to a moodle 2.0 theme?

by Jeff Vas -

Hi Tim,

This doesn't work in Moodle 2.4 anymore?

Anybody knows how to center a block in the center?

Thanks