Expand course categories by default on page load on course/index.php

Expand course categories by default on page load on course/index.php

by Com Pharm -
Number of replies: 6

Hi there, 

Is there any way to force the course categories to be expanded on page load by default? Currently all the drop-downs are collapsed on load, like this:

Collapsed

But we would ideally like them expanded, like this, as soon as the user opens the page:

Expanded

It should then be up to the user to collapse them if they want to, but on every load or refresh of the page, they should be expanded by default.

We're using the Moove theme, and this expansion should be applied to the course/index.php page.

I've read so much about overriding the PHP course renderer, or potentially overriding the javascript, but I am no where near an expert on PHP nor JS so would very much appreciate any (and as much) help as any one is able to provide! 

We have tried changing the course renderer php file but nothing happens, either we're doing something wrong or this isn't the way to tackle this issue!

Any advice would be greatly appreciated - thanks in advance!

Average of ratings: -
In reply to Com Pharm

Re: Expand course categories by default on page load on course/index.php

by David Saylor -
I located where the categories are being collapsed in the renderer. You can force the categories to be opened when the page is loaded by changing
if ($chelper->get_subcat_depth() > 0 && $depth >= $chelper->get_subcat_depth()) {
to

if (false && $chelper->get_subcat_depth() > 0 && $depth >= $chelper->get_subcat_depth()) {
(Shown below)

Original Function
Original function

Modified
Modified Function

You could make this modification directly in the renderer but you can prevent a core edit and make your upgrades easier by overriding the renderer via the theme. If the Moove theme has already overridden this function, then you will have to modify it in the theme to see the changes.
Average of ratings: Useful (1)
In reply to David Saylor

Re: Expand course categories by default on page load on course/index.php

by Com Pharm -
This worked! Thank you so much!

Just out of curiosity, how would we override the renderer via the theme?

Thanks again for your help!
In reply to David Saylor

Re: Expand course categories by default on page load on course/index.php

by Com Pharm -

Hi David,

We've just updated our Moodle to 3.7.1+, whilst this still works (and the Categories are expanded by default) it's now causing all the courses to be hidden, and only visible by selecting a "view all courses" hyperlink that appears.

This is how we want it to display:

1

but by adding 'false &&' to that section of code you advised on previously, on v3.7.1+, it's now appearing like this:

2

Any help you - or anyone - can give would be most appreciated!

Thank you!

In reply to Com Pharm

Re: Expand course categories by default on page load on course/index.php

by Gustavo Torres -

I have the same issue. Have you fixed it?

In reply to Gustavo Torres

Re: Expand course categories by default on page load on course/index.php

by Com Pharm -

Hi, yes we did manage to fix this. Here's how:


Update applied to: \course\renderer.php

 1) Force categories open

Amend:

if ($chelper->get_subcat_depth() > 0 && $depth >= $chelper->get_subcat_depth()) {

 to

 if (false && $chelper->get_subcat_depth() > 0 && $depth >= $chelper->get_subcat_depth()) {

 

2) Expand all courses

Amend:

 $coursedisplayoptions['nodisplay'] = true

 to

 $coursedisplayoptions['nodisplay'] = false


Hope this works for you too!

Average of ratings: Useful (2)
In reply to Com Pharm

Re: Expand course categories by default on page load on course/index.php

by Gustavo Torres -
Thank You so much, it worked!!!