Hide blocks from guests

Hide blocks from guests

by Nikki Macfarlane -
Number of replies: 3

I would like to be able to hide the Main menu block from guests. In this block I have the main student forum and general chats listed which i do not want guests looking at. Can I have these display once someone has logged in but not before?

Alternatively, can I add resources to other blocks and have these only display when someone has logged in?

Finally, I would like the main menu (or whatever I end up using for the chats and forums as above) to display on every page, not just the front one when people have signed in. So, for example, once they click on one of their courses the same block appears. Not sure how to do this. Any ideas?

Thanks, Nikki

Average of ratings: -
In reply to Nikki Macfarlane

Re: Hide blocks from guests

by John Papaioannou -
For your first question, you can make a small code modification to achieve what you want.

Open /blocks/site_main_menu/block_site_main_menu.php.

Find:
if (empty($this->instance)) {
    return $this->content;
}

Immediately afterwards, add:

if (isguest()) {
return $this->content;
}

And you are set. smile

For your second question, at this time no, you cannot.

Finally, you cannot have the main menu display in every page. The closest you can get to it with standard Moodle tools is to create an HTML block in each course, and copy the same HTML into each one. This HTML will be whatever you need to display your navigation menu; you can even use "view source" from your web browser, find the HTML for the site main menu block, and copy paste it in your custom HTML blocks "as is". That should result in an pixel-perfect copy of the main menu block. cool

In reply to John Papaioannou

Re: Hide blocks from guests

by Nikki Macfarlane -
Thanks Jon. Much appreciated. Will have to start learning how to code my own blocks!
In reply to John Papaioannou

Re: Hide blocks from guests

by Nikki Macfarlane -

Jon,

I tried changing the code in the block_site_main_menu.php as you suggested but no change. Whne the page first appears, i.e. nobody logged in, the participants list can be viewed. If you log in as a guest, it can also be viewed. I will have to remove the block altogether if I can't find a way around this as I cannot have all my students details viewable by the public. And if I remove it then this means there is no way for students to see the full list of all other studentsd as they are all in groups on the courses themselves. Any other ideas?

You can see what I mean here:

www.childbirthinternational.com/study