secondary menu links

secondary menu links

by Dean Howard -
Number of replies: 14

im trying to add a  menu option to the secondary menu navigation bar that can be found on the course pages, 




i can't find any reference to secondary menu or the menu names in the root directory can anyone point me in the right direction ?. 

moodle: version 4.0.1
theme: boost 

p.s is there some sort of developer documentation to find where all these mustache file link to so its easier to find files 🙄

Average of ratings: Useful (1)
In reply to Dean Howard

Re: secondary menu links

by Umme Kawser Sinthia -

Hi Dean,

You can add secondary menu links by using this function extend_navigation_course. Just put the given code on your lib.php file of any plugin and you'll see a link is created on the "More" section of course secondary menu. Replace the "plugintype" and "pluginname" to your desired plugin type and name of the plugin respectively.

function plugintype_pluginname_extend_navigation_course(navigation_node $navigation) {
global $PAGE;
$node = navigation_node::create(get_string('pluginname', 'plugintype_pluginname'),
new moodle_url('/plugintype/pluginname/index.php', array('courseid' => $PAGE->course->id)),
navigation_node::TYPE_SETTING,
null,
null,
new pix_icon('i/competencies', ''));
$navigation->add_node($node);
}
You can also see this reference documentation for extending navigation https://docs.moodle.org/dev/Callbacks 


Best regards.

Sinthia


 

Attachment Screenshot from 2022-07-22 15-30-10.png
Average of ratings: Useful (2)
In reply to Umme Kawser Sinthia

Re: secondary menu links

by Dean Howard -
thanks i ended up adding some html to the moremenu.mustache file so that it displays in the same row as the menu options.

another quick thing regarding the secondary navbar, is there a away to edit the css separately from the primary navbar ? every time i style the secondary nav it changes the primary nav too because they both share the same div elements eg ( moremenu navigation observed, moremenu-630e0aa2a948b-nav-tabs, role="menubar", class="nav more-nav nav-tabs") etc ?
Average of ratings: Useful (1)
In reply to Dean Howard

Re: secondary menu links

by Umme Kawser Sinthia -
Yes, you can add CSS separately for both Primary and Secondary Navbar. For styling the secondary navbar try using this class " .secondary-navigation .navigation .nav-tabs .nav-link " in your css file... For a quick view you can add it on the moremenu.scss file of boost theme..
eg.
.secondary-navigation .navigation .nav-tabs .nav-link {
background-color: red;
}


Regards,
Sinthia
Average of ratings: Useful (2)
In reply to Umme Kawser Sinthia

Re: secondary menu links

by F. Koch -

Hello Sinthia,

this works not in a block plugin or local plugin.

Is this intentionally?

Thank you

Florian

Moodle: 4.1

Theme: Boost

In reply to F. Koch

Re: secondary menu links

by F. Koch -
After restarting moodle it works in the block plugin, but still not in the local plugin.
In reply to F. Koch

Re: secondary menu links

by Umme Kawser Sinthia -
Hello Florian,
I have tried the same code from my previous comment (in lib.php file) for local plugin in moodle 4.1+ version and it works perfectly for me. I think you should install a new moodle in your PC and try it again...
You can also check the documentation https://docs.moodle.org/dev/Callbacks , where it is stated that this function works for all type of plugins. Hope this works for you too...

Best regards.
Sinthia
In reply to Umme Kawser Sinthia

Re: secondary menu links

by F. Koch -

Hello Sinthia,

it works in mod after bumping the version. In admin/tool this was not necessary.

Thank you

Florian

In reply to F. Koch

Re: secondary menu links

by Paolo Oprandi -
This is cool.

I wanted to add badges to the secondary navigation of the front page. But Moodle doesn't appear to be picking up the function even if I put it in badges/lib.php. Any thoughts?

badges_extend_navigation_frontpage(navigation_node $navigation)

In reply to Paolo Oprandi

Re: secondary menu links

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers
Check the developer documentation or look at the code to see if badges are supported in terms of extending navigation on the frontpage, i.e. a search of the PHP with the 'extend_navigation' string is a place to start.
Average of ratings: Useful (1)
In reply to F. Koch

Re: secondary menu links

by Paolo Oprandi -
has anyone worked out how, having added an item to the secondary navigation, you add secondary navigation to the page?
In reply to Umme Kawser Sinthia

Re: secondary menu links

by Mustafa Hajjar -
I just tried it in 4.1+ and works for me as well. Thanks...

Is there a way to change the order in the More menu or bring a tab to the main secondary navigation for local plugins yet?
Also, what's the use of passing an icon to the node creation when it is not displayed? i.e. pix_icon('i/competencies', ''))

Thanks,
Mustafa
In reply to Mustafa Hajjar

Re: secondary menu links

by Umme Kawser Sinthia -
Hello Mustafa,
I'm not sure about the change the order of more menu. I couldn't find how to do that, when I was working on it. Let me know if you get any solutions regarding that.
About the pix_icon part, all the other navigation has the icon added. So, I added it too but its an optional thing, you can pass 'null' as well instead of 'pix_icon' and the function will work fine...

Regards,
Sinthia
In reply to F. Koch

Re: secondary menu links

by Paolo Oprandi -
Note for blocks: you need to use the singular block rather than the plural blocks: block_{pluginname}_extend_navigation_{navcontext}