General developer forum

 
 
Picture of Niranjan eAbyas
Changes in the Navigation Block
 

Hi I am using the moodle2.0.1 stable version. I need the few changes in the "Navigation" block. Is it posible to  remove the "My home" and the "Site Pages" links from the Navigation block. If so what are the steps that i need to follow up.

Can any one help me up with this issue....

Niranjan

 
Average of ratings:Useful (1)
Picture of Mark Andrews
Re: Changes in the Navigation Block
 

Hi Niranjan,

Did you manage to get any further with this? I would also like to be able to customise what is displayed in the navigation and settings blocks.

Regards

Mark

 
Average of ratings: -
Picture of Niranjan eAbyas
Re: Changes in the Navigation Block
 

Hi mark,

I am customising the navigation block as per the requirement for our project. I am working on that. Once it is done I will post it here.

 
Average of ratings: -
Picture of Mark Andrews
Re: Changes in the Navigation Block
 

Hi Niranjan,

That would be great.

Thanks

Mark

 
Average of ratings: -
Picture of Lavanya Manne
Re: Changes in the Navigation Block
 

Hi,

How can we call only courses function from naviagtion block in my custom block. Could anyone help me?


 
Average of ratings: -
Picture of Alexander Fedorov
Re: Changes in the Navigation Block
 

Hi. Niranjan.

Try to see /lib/navigationlib.php There you can find class global_navigation and function initialise().

There

  • $this->rootnodes['home'] - My Home level
  • $this->rootnodes['site'] - Site Pages level.

So, the solution is out there. Try to comment them, but do it carefully, because there may be problems in global navigation.

 
Average of ratings: -
Picture of Anirban Nath
Re: Changes in the Navigation Block
 

1 sugesstion smile Nieranjan and Alex bro..

Use /put    $this->rootnodes['site']->remove();   to remove 'site' , after this line $this->rootnodes['users'];

eg:For  Removing myprofile wud be $this->rootnodes['myprofile']->remove();

 

hope its helps someone..happi coding guystongueout

 
Average of ratings: -
Picture of Haris Mol
Re: Changes in the Navigation Block
 

I ve been looking for the last 5 hours how to remove the annoying Site Pages empty link and the above didnt work for me but it showed me the right way...

After many hours of searching and testing i finally got this solution

In moodleroot/lib/navigationlib.php

in about line 1125 (or near there) you ll find this code

// Remove any empty root nodes
foreach ($this->rootnodes as $node) {
// Dont remove the home node
if ($node->key !== 'home' && !$node->has_children()) {
$node->remove();
}
}

edit these lines so to temove all links except the ones you want by using the same technique above

// Remove any empty root nodes
foreach ($this->rootnodes as $node) {
// Dont remove the home node
if ($node->key !== 'home' && $node->key !== 'myprofile' && $node->key !== 'mycourses' ) {
$node->remove();
}
}

 

the names of the nodes(menu options) you can find them in about line 919 by checking the following code

$this->rootnodes['site'] = $this->add_course($SITE);
$this->rootnodes['myprofile'] = $this->add(get_string('myprofile'), null, self::TYPE_USER, null, 'myprofile');
$this->rootnodes['mycourses'] = $this->add(get_string('mycourses'), null, self::TYPE_ROOTNODE, null, 'mycourses');
$this->rootnodes['courses'] = $this->add(get_string('courses'), null, self::TYPE_ROOTNODE, null, 'courses');
$this->rootnodes['users'] = $this->add(get_string('users'), null, self::TYPE_ROOTNODE, null, 'users');

I am a real amateur in php and i am not sure if this is a good solution or just an amateur's solution but the truth is that is working and because after many hours of searching in moodle forums i didnt manage to get a solution to this common question i hope this post will help many newbies like me!

 
Average of ratings:Useful (1)
Picture of Thomas Hanley
Re: Changes in the Navigation Block
 

Hi Haris,

Another possibility is to use  NetSapiensis' contributed Course Menu block instead of the core Navigation block. As I have zero PHP skills I have hacked this with CSS. There was a discussion in the Using Moodle forum here about removing items fromthe core Navigation block:

http://moodle.org/mod/forum/discuss.php?d=180982#p796741

...and in the forum for the Course Menu block where I posted the CSS which I used:

http://moodle.org/mod/forum/discuss.php?d=169107#p796143

~thomas

 
Average of ratings: -
Picture of Lavanya Manne
Re: Changes in the Navigation Block
 

Hi Haris Mol,

1. How could we hide home . If we hide home, going to else 'myhome' is  

    getting displayed. I want to hide both home and myhome

2. How could we hide General as thisn't a major rootnode.

3. I need to add icons to my custom links, for ex

$this->rootnodes['myreports'] = $this->add(get_string('myreports','blog'), new moodle_url('/grade/report/user/view.php?id='.$USER->id.''), self::TYPE_SETTING, null, 'myreports');

and how can we add icon here.

 

Thanks and Regards,

Lavanya Manne

   

 

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Changes in the Navigation Block
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers

You can do this by overriding the renderer for the navigation block. See http://docs.moodle.org/dev/Themes_2.0_overriding_a_renderer that explains overriding renderers in general.

 
Average of ratings: -
Picture of Lavanya Manne
Re: Changes in the Navigation Block
 

Hi Haris Mol,

Can we show different background colors for each category, course, section, activities and resources for navigation block.

 
Average of ratings: -
Rosario playing soccer
Re: Changes in the Navigation Block
Group Particularly helpful Moodlers

Sorry, I wrote a siteNavigation Block for Moodle 1.9 myself (http://moodle.org/mod/forum/discuss.php?d=103703 and myCourses Block http://moodle.org/mod/forum/discuss.php?d=67494) but I did not have time to delve into the code of navigation block of 2.x yet.

But if the proposed modifications of the code work, there is nothing to be feared, as you can revert back at any time. Be only sure to back up the original files and maybe restore them back before you upgrade to new Moodle Versions later on. And of course never test such things on your production server.

Rosario

 
Average of ratings: -
Picture of Juan Leyva
Re: Changes in the Navigation Block
Group DevelopersGroup Moodle HQGroup Particularly helpful Moodlers

In one of my plugins I manipulate the navigation block and delete several nodes, here you have some lines that can be usefull for you:

https://github.com/jleyva/moodle-local_ltiprovider/blob/master/lib.php#L66

 
Average of ratings: -
Ray Lawrence
Re: Changes in the Navigation Block
Group Particularly helpful Moodlers

This can be achieved using CSS and doesn't require the managment of core code changes. The code below was posted in another discussion by Justin Mastic.

/* Remove items from navigation block */

/* Remove "My home" */
.block_navigation .type_setting.depth_2 { display: none; }

/* Remove "Site Pages" */
.block_navigation .type_course.depth_2  { display: none; }

/* Remove "My Profile" */
.block_navigation .type_user.depth_2 { display: none; }

/* Remove "Courses" */
.block_navigation .type_system.depth_2 { display: none; }

 
Average of ratings:Useful (5)
Picture of Philip Watland
Re: Changes in the Navigation Block
 

Thanks for this information.  Works great!

 
Average of ratings: -
Picture of Kim Park
Re: Changes in the Navigation Block
 

I am using Moodle 2.6.1 and would like to hide the Site Pages from The Navigation Block.  I see the CSS code from this post but I've never had to add any CSS code before for my server and am unfamiliar with where, exactly, I add it.

I'm using the Serenity Theme and when I did a search on the Site Admin block for CSS, the Serenity Theme does not show?   Most other themes do, so I'm not sure why Serenity doesn't show as well?

I realize this is an old post, but if someone out there can give a few more specifics, that would be much appreciated

-CSS Newbie (Kim)

 

 
Average of ratings: -