Themes

Different Custom Menus for Categories

 
 
Picture of Laura Koepke
Different Custom Menus for Categories
 

We are developing our 2.0 Moodle site and I like the new custom menu.  Creating and updating the menu is easy since the user does not have to deal with backend files.  BUT...we have a different branded theme for each school and I assign the school's theme to a category.  My questions are, 1) can we have more than one custom menu and if so, how do I do that; and 2) if not, do I remove the custom menu code from each theme and replace it with my own menu and if so, are there any tutorials that I can follow? 

 
Average of ratings: -
Picture of Richard Oelmann
Re: Different Custom Menus for Categories
Group DevelopersGroup Particularly helpful MoodlersGroup Testers

There's an issue in Tracker which I believe has just been pushed into the next release which will enable themes to be set up so that they can override the default custommenu. I think this might be just what you are looking for.

The code is already given on the tracker page so you may be able to just ammend your existing installation and themes to use it.

http://tracker.moodle.org/browse/MDL-31043

Richard

 
Average of ratings: -
Picture of Laura Koepke
Re: Different Custom Menus for Categories
 

Thank you Richard.  I am working with afterburner and I was able to create the settings.php file and copy the code from MDL-31043 into it.  That allowed me to create the new menu - first part was a success!  I then adjusted the code in the default.php file but I'm still getting the parent menu.  The afterburner default.php has another line of code after $custommenu.  I'm including it here.  Does that line also need adjusting?

$hascustommenu = (empty($PAGE->layout_options['nocustommenu']) && !empty($custommenu));

 

 
Average of ratings: -
It's only an avatar...
Re: Different Custom Menus for Categories
Group DevelopersGroup Documentation writersGroup Particularly helpful MoodlersGroup Testers

It should look like this...

$custommenu = $OUTPUT->custom_menu($PAGE->theme->settings->custommenuitems);
$hascustommenu = (empty($PAGE->layout_options['nocustommenu']) && !empty($custommenu));

 
Average of ratings: -
Picture of Laura Koepke
Re: Different Custom Menus for Categories
 

Mary,

Following the directions in Richard's post, I went to MDL-31043 and made the change to $custommenu.  That didn't work.  Thus my reply to him.  My default.php has the exact code you show in your post - still not working.  I'm not sure what you are referring to on following instruction and doing as you are told...sounds a bit harsh as I'm not looking for an alternate way of doing something.

 

 
Average of ratings: -
It's only an avatar...
Re: Different Custom Menus for Categories
Group DevelopersGroup Documentation writersGroup Particularly helpful MoodlersGroup Testers

Sorry that was me trying to be funny! smile (I'll remove it)

Have you done everything that Dan tells you to do in MDL-31043 to get this to work?

He was referring to Afterburner theme, as not all themes have a settings.php

So assuming you have done everything to the letter changing moodle/lib/outputrenderers.php and adding the extra information in the default.php plus adding the few lines to the settings.php and you are satisfied it is all correct, then you need to go to...

Settings > Site Administration > Development > Purge all caches

That done you will need to refresh your browser screen and clear the browser cache too if you are not in the habit of deleting it often.

To see the changes you will need to go to...

Settings > Site Administration > Appearance > Themes and in the list of theme settings pages below you should see Afterburners name. Click on that link will bring you to that themes Custom Settings Page. Half way down that page you will see the Custom menu text area which will be empty.

Now...whatever you write in the menu will block out the Global menu which (if you set one) in the Admin Theme settings page.

Of course if you are not using Moodle 2.2 you will not have the required settings.php page unless you copied that too from somewhere? However, there is more to the settings page. There is the lang/en/theme_afterburner.php to change as well, so what you are trying to do may not work, if you don't have the correct version of the theme.

I hope that helps?

Cheers

Mary

 
Average of ratings: -
Picture of Laura Koepke
Re: Different Custom Menus for Categories
 

Thanks Mary for your reply.

We are using Moodle 2.1.2 and I've tried this on two themes, Afterburner and Fusion, with no success.   I am running in designer mode but I did purge all the caches as well and I did add a new menu options at the theme level.  MDL-31043 says it affects 2.2 and is fixed in 2.3.  Since we are in the beginning phases of the conversion process, we will upgrade to 2.3 and see if that helps.  Thanks again Mary.

 
Average of ratings: -
It's only an avatar...
Re: Different Custom Menus for Categories
Group DevelopersGroup Documentation writersGroup Particularly helpful MoodlersGroup Testers

Hi I just noticed a mistake in my last comment...I said Moodle 2.1 (this is when Afterburner was added to Moodle) I did the updates for the settings page for the Moodle 2.2 release.  There are more changes planned for the 2.3 release.  This will hopefully be in it. We may add this new feature to other themes, but I am not clear about that yet. However, at least the mechanisms will be there in Moodle system files should anyone what to try it out.

Cheers

Mary

 
Average of ratings: -
Picture of Laura Koepke
Re: Different Custom Menus for Categories
 

Mary, thanks again for your quick responses.  I upgraded to 2.2 yesterday and went through the steps in MDL-31043 but I'm still getting the default menu.  I tried it with a different theme (fusion) and it didn't work either.  I have purged all of the theme caches and even tried removing the default menu to see if it would kick start the theme's menu but still no go.  I am so close to accomplishing what I need...any idea what I might be missing?  Are there other places besides the default.php and settings.php that need to be changed?

 
Average of ratings: -
It's only an avatar...
Re: Different Custom Menus for Categories
Group DevelopersGroup Documentation writersGroup Particularly helpful MoodlersGroup Testers

Hi Laura,

The fix is not in any of the theme yet. The fix has only been added to Moodle (master) 2.3 which has not yet been released.

So to get this to work you need to make changes to the your moodle install...

The changes need to be made in the following...

Moodle Core:
moodle/lib/outputrenderers.php

Information about moodle/lib/outputrenderers.php is as follows...

https://github.com/danmarsden/moodle/compare/master...master_MDL-31043

Moodle Theme:
moodle/theme/afterburner/settings.php
moodle/theme/layout/default.php
(or whichever theme you want to try this out in providing it has a settings.php)

Changes to the themes will not work without the changes to the lib/outputrenderers.php.

Hope this helps?

Mary

 
Average of ratings:Useful (1)
Picture of Laura Koepke
Re: Different Custom Menus for Categories
 

YOU ARE BRILLANT!!!  It worked.  I just needed to change the code in outputrenderers.php and it all works as expected.  I missed that in the original post.  Thank you again for your patience and help!!!

 
Average of ratings: -
It's only an avatar...
Re: Different Custom Menus for Categories
Group DevelopersGroup Documentation writersGroup Particularly helpful MoodlersGroup Testers

YEAH!!!

 
Average of ratings: -
Picture of Jennifer Cramton
Re: Different Custom Menus for Categories
 

I'm really glad other people were looking to do this exact thing! Is this also supposed to work if I have different themes for different courses (which are in the same category)?
I've checked and double checked that I have entered all of the information correctly, and the new menu is still not showing up.... I'm using aardvark, so there's no default.php. Made those changes in general.php instead. 

 
Average of ratings: -
It's only an avatar...
Re: Different Custom Menus for Categories
Group DevelopersGroup Documentation writersGroup Particularly helpful MoodlersGroup Testers

Hi,

Laura said much the same but found that she was missing the vital element..that is you need to modify moodle/lib/outputrenderers.php in order to make this work!!!

See the previous posts for the link to Dan Marsden's GitHub.

Cheers

Mary

 
Average of ratings: -
Picture of ces moce
Re: Different Custom Menus for Categories
 

Is there a way to do it with a theme that doesn't have a setting.php?

 
Average of ratings: -
It's only an avatar...
Re: Different Custom Menus for Categories
Group DevelopersGroup Documentation writersGroup Particularly helpful MoodlersGroup Testers

Hi,

You can ADD a settings page to a theme...in this case that code which goes into the settings page would be the only code...but it will (or should) work. So just add the following.

<?php

defined('MOODLE_INTERNAL') || die;

if ($ADMIN->fulltree) {

    // Theme overrides custom menu
    $name = 'theme_afterburner/custommenuitems';
    $title = get_string('custommenuitems', 'admin');
    $description = get_string('configcustommenuitems', 'admin');
    $default = '';
    $setting = new admin_setting_configtextarea($name, $title, $description, $default);
    $settings->add($setting);
}

YOU NEED TO CHANGE

  $name = 'theme_afterburner/custommenuitems';

to reflect the name of YOUR theme

Hope this helps?

Mary

EDITED: 8th May 2012 @22:31 - BST

 
Average of ratings: -
Ray Lawrence
Re: Different Custom Menus for Categories
Group Particularly helpful Moodlers

I've looked in a HEAD install and can't see the place to change the category custom menu. It must be obvious but I can't find it. wide eyes

 
Average of ratings: -
It's only an avatar...
Re: Different Custom Menus for Categories
Group DevelopersGroup Documentation writersGroup Particularly helpful MoodlersGroup Testers

If you are looking at changing ../lib/outputrenderer.php so you can add this new feature to a theme you will find the code you need to add here...

https://github.com/danmarsden/moodle/commit/0f6d934941b9ff21846ff8808b6d50be9df54eaf

Mary

 
Average of ratings: -
Picture of ces moce
Re: Different Custom Menus for Categories
 

i m using moodle 2.3 so normally the changes has been done on outputrenderer.php but i still can t figure out where to set the custommenu on my template

 
Average of ratings: -
It's only an avatar...
Re: Different Custom Menus for Categories
Group DevelopersGroup Documentation writersGroup Particularly helpful MoodlersGroup Testers

Checkout the new theme I added to the Moodle Themes directory. It's called Aaradyha.

HTH

Mary

 
Average of ratings: -
Picture of ces moce
Re: Different Custom Menus for Categories
 

in fact now thanks to settings.php i can see the custommenuitems option in my theme settings, so i ve set some theme items but it doesn't show

 
Average of ratings: -
It's only an avatar...
Re: Different Custom Menus for Categories
Group DevelopersGroup Documentation writersGroup Particularly helpful MoodlersGroup Testers

Are you using the latest release of Moodle 2.3?

Also did you amend your layout files for $hascustommenu becaus you need this code to replce what is in general.php and frontpage.php

$custommenu = $OUTPUT->custom_menu($PAGE->theme->settings->custommenuitems);
$hascustommenu = (empty($PAGE->layout_options['nocustommenu']) && !empty($custommenu));

The make sure you go to Site Administration > Development > Purge all caches

 
Average of ratings: -
Picture of Flávio Camargo
Re: Different Custom Menus for Categories
 

Staff have good news!

For the Moodle version 2.4 is not necessary to change the file 'outputrenderers.php'. you change only two files that are inside your settings.php and the default.php template (located in the folder layout).

Add the settings.php file of your template information:

$ name = 'theme_afterburner / custommenuitems';
$ title = get_string ('custommenuitems', 'admin');
$ description = get_string ('configcustommenuitems', 'admin');
$ default ='';
$ setting = new admin_setting_configtextarea ($ name, $ title, $ description, $ default);
$ settings-> add ($ setting);

* In this example I changed the theme afterburner then according to your template change the name.

Then in your theme file theme / layout / default.php find this line:
OUTPUT = $ $ custommenu-> custom_menu ();
and replace it with this:
$ custommenu = $ OUTPUT-> custom_menu ($ PAGE-> theme-> settings-> custommenuitems);

Ready then just run to hug!! =)

 
Average of ratings: -