Themes

Adding a new block region in Solstice theme

 
Picture of g k
Adding a new block region in Solstice theme
 

Specifically, I have been trying to create a block region exactly where the "topic section" is located or directly above it. Results have been horrible thus far.  I have been reading that this is not so straight forward. There is probably some truth to this.  Could anyone point me in the right direction?

 
Average of ratings: -
It's only an avatar...
Re: Adding a new block region in Solstice theme
Core developersDocumentation writersParticularly helpful MoodlersPlugin developersTesters

Adding a new block region is pretty straight forward, however, it's not practicable on sites where users can dock blocks, as this is where the problem starts with respect to custom blocks regions.

Here's what you need to do.

Basically you need to see what the code looks like for either side-pre or side-post and copy that style.

Lets assume you are going to call your new block region 'fred' for want of a name. The name it self does not matter just as long as it is no more than 10 characters in length.

ADD the following to each of your layout files. (frontpage.php / general.php)

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

Nex you need to add this line in the top of the layout file where you see other similar looking lines of PHP.

$hassidefred = (empty($PAGE->layout_options['noblocks']) && $PAGE->blocks->region_has_content('side-fred', $OUTPUT));

And that's it! The major thisng is that it HAS to follow that syntax otherwise it wont work in Moodle 2.3/2.4/...

To get it to show up in the center you need to add the block region part of the code at this point in the layout just before the main content is output...

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

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

EDITED:

I almost forgot you will also need to add 'side-fred' to your theme's config.php like so...for each of the layout regions you want your custom block to be visible.

'regions' => array('side-pre', 'side-post', 'side-fred'),

I hope this helps?

Mary

 
Average of ratings: -
Picture of g k
Re: Adding a new block region in Solstice theme
 

"Fred"?  Ha!  I will try this.  big grin Thanks!

 
Average of ratings: -
Picture of g k
Re: Adding a new block region in Solstice theme
 

Mary,

Thanks again. This basically works but for some reason when I move the block to the center region, it duplicates the block.  I would like to have it right between the "settings" and "calendar" blocks as show, and not above as shown at full width.

 

 
Average of ratings: -
Picture of g k
Re: Adding a new block region in Solstice theme
 

Nevermind....Brain cramp! smile

 
Average of ratings: -
It's only an avatar...
Re: Adding a new block region in Solstice theme
Core developersDocumentation writersParticularly helpful MoodlersPlugin developersTesters

That's an easy fix so don't despair.

You need to move the closing div beneath the main content output. I should have said that before.

Give a minute or two and I'll get the code for you...

 
Average of ratings: -
Picture of g k
Re: Adding a new block region in Solstice theme
 

Actually, your directions were crystal clear.  I figured out what I was doing wrong. I am thick-headed sometimes. That's what I meant by "brain cramp".  I ended up doing pretty much what you indicated before.  It worked out fine!  smile Thanks again!

 
Average of ratings: -
It's only an avatar...
Re: Adding a new block region in Solstice theme
Core developersDocumentation writersParticularly helpful MoodlersPlugin developersTesters

LOL@BrainCramp

Glad it all working now...

Cheers

Mary

 
Average of ratings: -
It's only an avatar...
Re: Adding a new block region in Solstice theme
Core developersDocumentation writersParticularly helpful MoodlersPlugin developersTesters

OK here's the fix...

 For Moodle 2.3 

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

        <?php if ($hassidefred) { ?>
        <div id="region-fred" class="block-region">
            <div class="region-content">
                <?php echo $OUTPUT->blocks_for_region('side-fred') ?>

                <?php echo $OUTPUT->main_content() ?>
            
            </div>
        </div>
        <?php } ?>            

        </div>
    </div>
</div>

 For Moodle 2.4


<div id="region-main-wrap">
    <div id="region-main">
        <div class="region-content">
        
        <?php if ($hassidefred) { ?>
        <div id="region-fred" class="block-region">
            <div class="region-content">
                <?php echo $OUTPUT->blocks_for_region('side-fred') ?>  

                <?php echo $coursecontentheader; ?>
                <?php echo $OUTPUT->main_content() ?>
                <?php echo $coursecontentfooter; ?>

            </div>
        </div>
        <?php } ?>
        </div>
    </div>
</div>

 
Average of ratings: -