Forums | Mahara Community
Support
/
Which file displayed the main navigation menu?
23 December 2013, 8:17
I wanted to change my navigation menu, but I cannot find which file controls this. I was able to get as far as looping through $mainnav, but I could not figure out where $mainnav was set.
I am trying to change the "content", "portfolio", "Groups" and its sub-menus.
Melissa
23 December 2013, 9:09
Hello Melissa,
Look in htdocs/lib/web.php around line 2330 where it says "* Returns the entries in the standard user menu". You'll find the menu there.
Cheers
Kristina
23 December 2013, 14:44
It looks like there is a way to override the main menu. Where exactly would that code be placed? Is it a file in a template? What file would it be, and what would the function name be?
Melissa
24 December 2013, 8:22
Hello Melissa,
I don't know if you could change the menu as part of a local change or if you'd need to change it in lib/web.php around the lines that I mentioned earlier.
When you look at the lib/web.php file, you see that each menu item is described by an array and I suspect you just have to overwrite that an place your own URLs and lang strings in there to achieve the outcome.
Cheers
Kristina
24 December 2013, 9:14
From the lib/web.php file is the following code:
// local_main_nav_update allows sites to customise the menu by munging the $menu array.
if (function_exists('local_main_nav_update')) {
local_main_nav_update($menu);
}
$menu_structure = find_menu_children($menu, '');
That looks like you can create a local version of the main navigation menu. I don't know the line number, because the editor that I am using does not show that.
Melissa
24 December 2013, 14:30
Yes, as you've noticed, you can optionally define a function local_main_nav_update(&$menu) (the recommended location for it is in local/lib.php), and have it alter the contents of the $menu variable, by reference.
Cheers,
Aaron
26 December 2013, 13:34
Can you please post an example of this file? I tried to create one and it did not work correctly. Basically I just want to move to the top level a couple of functions that I use all of the time "Files", "Pages", and "Collections".
Thank you,
Melissa
31 December 2013, 11:32
Hi Melissa,
Moving a submenu item to be a main menu item has a bit of complication as the menu item array name contains the main and submenu parts, eg for 'Files' it's array name is 'content/files'. But with a few tweaks we can get things working.
Here is an example of moving the 'Files' menu item to the top level.
In local/lib.php add this:
function local_main_nav_update(&$menu) {
$menu['files'] = array (
'path' => 'files',
'url' => 'artefact/file/index.php',
'title' => 'Files',
'weight' => 40,
);
unset($menu['content/files']);
}
A higher weight number means futher to the right in the menu it will appear.
This will add 'Files' as a top level menu item and remove it from under 'Contents'.
To get it to be the highlighted menu item when you go to that page you will need to change this line in artefact/file/index.php
define('MENUITEM', 'content/files');
to
define('MENUITEM', 'files');
Hope that helps
Cheers,
Robert