Themes

Block or Change Custom Menu for a Course

 
 
Picture of Jonathan Konrad
Block or Change Custom Menu for a Course
Group Moodle Course Creator Certificate holders

My school division maintains one Moodle server for all of our schools. They use the custom menu items in the theme settings to create a navigation bar. However, this navigation bar now relates entirely to the division. I would like to setup all the courses for my school to show different navigation items. Changing the theme is easy, even customizing it to look like something built for our school is ok. My question; Is there a way to block the custom menu items of the site from showing up on my courses. Even better, is there a way for me to have my own custom items to show up for my courses without messing up the sites cutom menu items?

The server is running on linux. It is Moodle 2.6.2 Thanks for any tips.

 
Average of ratings: -
It's only an avatar...
Re: Block or Change Custom Menu for a Course
Group DevelopersGroup Documentation writersGroup Particularly helpful MoodlersGroup Testers

Yes and no...

  1. Yes there is a way to have a different menu in your moodle/my page which is different than the one in the rest of your site/division. This menu would be served via the theme itself in that the menu is added in the themes custom setting page moodle/theme/yourtheme/settings.php
  2. And No there isn't a way to to separate menu items that are specific to a user...well not easily.

The menu I am talking about is in the Aaradyha theme.

 
Average of ratings: -
Picture of Jonathan Konrad
Re: Block or Change Custom Menu for a Course
Group Moodle Course Creator Certificate holders

I found this document after I posted. It looked promising, but is quite in depth. Is all of this really needed? I tried to follow, but I cannot seem to get my own list showing.

http://docs.moodle.org/dev/Creating_different_custom_menu_bars_for_different_courses

I learned in all the layout files that if I simply delete the line "<?php echo $OUTPUT->custom_menu(); ?>" the menu no longer shows. I'll take that if it is all I can do, but I would rather leave that in place and have it show my items instead of the site. Where does it find the cutommenuitems? Can I redirect that process? Is it in the core-rendere.php file. Can I hijack this?

public function custom_menu($custommenuitems = '') {
// The custom menu is always shown, even if no menu items
// are configured in the global theme settings page.
global $CFG;

if (!empty($CFG->custommenuitems)) {
$custommenuitems .= $CFG->custommenuitems;
}
$custommenu = new custom_menu($custommenuitems, current_language());
return $this->render_custom_menu($custommenu);
}

 

I want to try to block a theme from reading the site custom menu items, and substitute my own list from a file stored in the theme. I am playing around with the elegance and the essential themes.

 

 

 

 
Average of ratings: -
It's only an avatar...
Re: Block or Change Custom Menu for a Course
Group DevelopersGroup Documentation writersGroup Particularly helpful MoodlersGroup Testers

Hi, I think that tutorial you linked to was written as a project by someone. However it is not as complicated as that, as you don't need to touch the renderer. In fact it has nothing to do with the renderer.

That tutorial is about creating a child theme to use as a course theme. You can then add the menu specific to that course in the child theme and then that menu is the one that shows up in the course pages and not the global one.

To add this menu all you need is ...

  1. a settings.php which contains these lines...
      // Theme overrides custom menu setting...
    $name = 'theme_child_theme/custommenuitems';
    $title = get_string('custommenuitems', 'admin');
    $description = get_string('configcustommenuitems', 'admin');
    $default = '';
    $setting = new admin_setting_configtextarea($name, $title, $description, $default);
    $settings->add($setting);
  2. a copy of a layout file preferably one that already exists in your theme that needs renaming and also this line adding to it just under the opening PHP tag... <?php

    $custommenu = $OUTPUT->custom_menu($PAGE->theme->settings->custommenuitems);
    $hascustommenu = (empty($PAGE->layout_options['nocustommenu']) && !empty($custommenu));
  3. Depending on where you want this menu to show you would need to add the file name to the $THEME->layouts found in the theme's config.php

That is more or less all you need to do.

If you checkout the Tiny Bootstrap Project theme you will see how I made it that the menu shown was determined by if you were logged in or not.

Hope this helps?

Mary

 
Average of ratings: -
It's only an avatar...
Re: Block or Change Custom Menu for a Course
Group DevelopersGroup Documentation writersGroup Particularly helpful MoodlersGroup Testers

Further to my last comment you also need to have this line where the custom menu is situated in the layout file...

<?php echo $custommenu; ?>
 
Average of ratings: -
Picture of Jonathan Konrad
Re: Block or Change Custom Menu for a Course
Group Moodle Course Creator Certificate holders

Thank you for taking the time to try to help me. I followed your steps. It resulted in the theme displaying the custom menu where I posted that last bit of code

<?php echo $custommenu; ?>

Cool. But it still displays the items as defined in the Moodle site settings. I already have that. In fact the theme I was playing with, already displays the custom menu. I want to display a course specific menu. Not the custom items from the site. So site menu:

Page A
-Page B
-Page C

In this course it shows;

Page ZZ
-Page FF
-Page GG

So a totally different list of custom menu items. A list I can read from a file in the theme folder. It is the content, not the style of the menu that I would like to change.

 
Average of ratings: -
It's only an avatar...
Re: Block or Change Custom Menu for a Course
Group DevelopersGroup Documentation writersGroup Particularly helpful MoodlersGroup Testers

I'll make up a theme so you can test it...as you seem to have only half of it working.

The place you add the Menu items to are in the settings page for the theme, which is different that the theme settings page found at Site Administration > Appearance > Themes > Theme settings

- this is normally where you add the global menu items.

Whereas in a theme that has both the ordinary menu and the 'mysuperduperthememenu' (to give it a name)  you would need to add the extra menu to this location in your moodle site...

Site Administration > Appearance > Themes > MySuperDuperThemeMenu' which is just a link to the Custom settings page for that theme assuming of course the theme you are using is called MySuperduperThemeMenu.

Sorry if this does not make sense but it's all rushed as I don't have time to explain properly.

If no menu items are added in the customised theme (ie. MySuperDuperThemeMenu settings page) then the standard 'global' menu is used.

Is that clearer?

Let me know if that 2nd menu shows up?

Cheers

Mary

 
Average of ratings: -
Picture of Helen Moraes
Re: Block or Change Custom Menu for a Course
 

Hi,

I have some issues I hope you can help me with.

I followed each steps provided by Mary, but using Elegance theme, with a Elegantchild child theme (found in Moodle.org) I can't have a different custommenu on differet themes.

I followed these instructions too:

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

https://moodle.org/mod/forum/discuss.php?d=193738

 

Problems:

1) Elegantchild has its own settings.php.

If I add to it (where?) this lines afetr php opening tag nothing seems to happen, but of course it could depend on the fact that other steps are missing; if I put it inside the document (e.g. at line 56 or line 79) I get a blank page.

$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);

So, I deleted old settings.php for child theme and created a new one with only this:

<?php

defined('MOODLE_INTERNAL') || die;

if ($ADMIN->fulltree) {

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

 

 

2) Assuming I have the settings.php above, I go forward and try with layout file. Elegantchild has no default.php file and no layout folder. If I create the folder and put a default.php in it (cloning from elegance theme, and changing

    theme_elegance_initialise_reader($PAGE);

    to

theme_elegantchild_initialise_reader($PAGE);

inside it (the only change I found), and then add 

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

after the opening php tag, I get some strange message in the rendered page of the child theme, something like

[MAIN CONTENT GOES HERE - ZvJFRzKKnS]

and navigation buttons stop working. This is the only thing I can see from now.

One more thing, I tried also the MDL-31043 change (that is a little different, MAYBE, from Mary's), but Elegance default.php has no

$custommenu = $OUTPUT->custom_menu();

but a

    <div id="moodle-navbar" class="navbar-collapse collapse">
        <?php echo $OUTPUT->custom_menu(); ?>
        <?php echo $OUTPUT->user_menu(); ?>

so I don't know how to change it to make it look like

$custommenu = $OUTPUT->custom_menu($PAGE->theme->settings->custommenuitems);

 

3) I tried to purge chaches, but after point 2) I can't browse site.

 

4) Mary wrote

Depending on where you want this menu to show you would need to add the file name to the $THEME->layouts found in the theme's config.php

Is this step I'm missing? I can't really figure out how to do this.

 

 

So, am I missing /doing wrong something? (I bet it's so!)

PS: I'm using Moodle 2.6.2. with Elegant / Elegantchild themes.

 
Average of ratings: -
Picture of Jonathan Konrad
Re: Block or Change Custom Menu for a Course
Group Moodle Course Creator Certificate holders

I'm trying again. I think I'm getting closer to understanding, but I've bumped in to a problem. When I put the code you indicate in my settings.php file in the theme I'm editing (Essential), my site administration fails to load (shows a very small, blank pop up box) and I cannot get in to anything under site administration. 

I read this page: https://tracker.moodle.org/browse/MDL-31043

It seems to provide very similar instructions. Following this yields the same result, a problem loading my site administration settings. That link also references changing something in outputrenderers.php . I'm not sure where that file is, or if I should replace something with the code given or add the code given.

I feel so close, I'd love to have a custom menu for a given theme that I could define in the theme settings page. I'd pay someone to do this small hack for me, but I do not know who! Thanks for any help you can give.

 
Average of ratings:Useful (1)