Remove items from navigation block?

Re: Remove Courses from navigation block for guests and users not logged in?

by Mustapha Hadid -
Number of replies: 3

In Moodle 3.2, I successfully done the same using the following snippet


<style>

[data-key='home'] { display: none; }            /* Remove "Site home" */

[data-key='calendar'] {display: none; }         /* Remove "Calendar" */

[data-key='5'] {display: none; }                /* Remove "Private files" */

</style>

Average of ratings: Useful (2)
In reply to Mustapha Hadid

Re: Remove Courses from navigation block for guests and users not logged in?

by Ben Laor -

I am also using 3.2 and this method works great!
I was wondering, how do you know which data-key to use?
Do you know of one to remove all the course sections?

In reply to Ben Laor

Re: Remove Courses from navigation block for guests and users not logged in?

by Ben Laor -

Since i work with Grid format for courses, i wanted to remove the course sections from the navigation menu.
Wrote a small js script that takes care of that (not tested everywhere yet, but works fine for me).
Important to reiterate this is for Moodle 3.2 with boost theme, and Grid course format.
Add it to "Site administration" -> "Appearance" -> "Additional HTML" inside the "Before BODY is closed" section:

<script>
var listGroup = document.getElementsByClassName("list-group")[0];
var listGroupItems = listGroup.getElementsByClassName("list-group-item")
for (var itemKey = 0; itemKey < listGroupItems.length; itemKey++) {
    var dataKey = listGroupItems[itemKey].getAttribute("data-key");
    if (dataKey == "mycourses") { break; }
    if(/^\d+$/.test(dataKey)) {
         listGroupItems[itemKey].style.display = 'none';
    }
};
</script>

ATTENTION! this script also removes the "private files" nav topic in all pages that aren't courses since its data key is a number(5) but that could easily be fixed with a simple "if" (i happen to not need "private files" as well so this works for me)

Average of ratings: Useful (2)
In reply to Ben Laor

Re: Remove Courses from navigation block for guests and users not logged in?

by Mustapha Hadid -

You get the point though, right?

I usually do use CSS Selector Helper for Chrome extension to help me find a unique CSS selector for an element, use it, it could help you alot!