Boost theme - how to hide sidebar by default?

Boost theme - how to hide sidebar by default?

by Chye Siaw -
Number of replies: 5

Moodle 3.2.1+

Hi, we are using the Boost theme on our Moodle website. It seems that the sidebar (containing navigation block) is open/closed depending on the user's last visit (ie if he left it open, next time he visits it remains open; vice versa).

Is there a way to hide the sidebar by default (every time the user visits the website), and only open when the button is clicked on?

This is to standardised everyone's view and also utilise the screen-width maximally.

Thanks in advance.


Edit: If you can point out where in the code we need to change that will be great.

Average of ratings: -
In reply to Chye Siaw

Re: Boost theme - how to hide sidebar by default?

by Dave Catlin -

I am not using the Boost theme, but I have the same issue.

In reply to Dave Catlin

Re: Boost theme - how to hide sidebar by default?

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hi Dave,

Silly question, but when the post refers to a piece of functionality that is only in the Boost theme then how can you have the same issue in another theme?

Kind regards,

Gareth

In reply to Gareth J Barnard

Re: Boost theme - how to hide sidebar by default?

by Dave Catlin -

Its not an issue with the theme.  I don't want to open a page with the sidebar open.

In reply to Dave Catlin

Re: Boost theme - how to hide sidebar by default?

by Chye Siaw -

The sidebar is dictated by the theme.

What theme are you using?


Anyway, I figured out where to alter the code in Boost:

Line 31-34 in theme/boost/layout/columns2.php

Change

if (isloggedin()) {

    $navdraweropen = (get_user_preferences('drawer-open-nav', 'true') == 'true');

} else {

    $navdraweropen = false;

}


To


if (isloggedin()) {

    $navdraweropen = false;

} else {

    $navdraweropen = false;

}


This will result in the sidebar being always closed on revisit regardless of its previous state that the user left it as.

Average of ratings: Useful (6)
In reply to Chye Siaw

Re: Boost theme - how to hide sidebar by default?

by Vladimir Gomez -

Hello Chye Siaw, everyone.

This worked for me with the side effect that it always closes the sidebar when changing pages (I wanted it to stay open if the user opened it to go to another section). To solve it, I added a variable to the session and tested for it on the if. This is the code:

if (isloggedin() && isset($_SESSION['alreadyloggedin'])) {
    $navdraweropen = (get_user_preferences('drawer-open-nav', 'true') == 'true');
} else {
    $navdraweropen = false;
    $_SESSION['alreadyloggedin'] = true;
}
Hope it helps somebodoy.

Regards,

Vlad.

Edit:
A slightly more efficient version of this code would be:


if (isset($_SESSION['alreadyloggedin'])) {
    if (isloggedin()) {
        $navdraweropen = (get_user_preferences('drawer-open-nav', 'true') == 'true');
    } else {
        $navdraweropen = false;
    }
} else {
    $navdraweropen = false;
    $_SESSION['alreadyloggedin'] = true;
}