Version 15 (modified by izzy, 10 years ago) (diff)



Notice: This plugin is unmaintained and available for adoption.


PS: - CSS work might be needed to fit your trac theme.


See it in action:

Bugs/Feature Requests

Existing bugs and feature requests for MenusPlugin are here.

If you have any issues, create a new ticket.

Download, Source

Download the [download:menusplugin zipped source], check out MenusPlugin from using Subversion, or browse the source with Trac.


As usual, configuration takes place in the trac.ini file. Most interesting things first - they are to be found in the [mainnav] section: Here you set up your menu items. Syntax is: <item_name>.<property> = <value> - where <item_name> is either the already existing handler (e.g. "wiki" for the wiki item, "tickets" for the tickets, "newticket" for the "New Ticket" item, a.s.o.) - or a term which must not exist for a brand new item to be introduced (as e.g. the "Team Tools" in the Examples section). A special case is e.g. top to make a new item appearing on top level.

Defining your menus in the [mainnav] section

So here come the available properties and their possible values:

PropertyDescriptionExample value
parentMake the item a sub-item to the one mentioned as valuetop
labelWhat should be written on the "button"Team Tools
hrefWhere the item should link to/report/1
enabledMust be set to 1 for self defined items to be shown. Can be set to 0 to (temporarily) disable an item.1
hide_if_no_childrenDon't display this (sub) menu if it has no children (e.g. the current user lacks the privileges for all sub-items)1
permFor items like reports, hide_if_disabled does not work, since this is no component. Though, it should not be displayed if it is not available. So you can handle this by defining the required permission.REPORT_VIEW
orderMove an item to the left/right. By default, all items have an order of 999 (who will ever reach 999 items must have done something wrong, really!). Use values from 1..999 to define positions. Use a negative value for an item you want to make sure it always comes first - and a value larger than 999 if it sould always come last.5
path_infoString to be matched with the request path info to decide whether a menu item should be displayed. Useful for context dependent items (e.g. in the ctxnav)/wiki

Missing here: inherit

Defining the behaviour in the [menu-custom] section

Here you can (re-)define (i.e. customize) the behavior of MenusPlugin. Usually, you won't need that - since the defaults are fine. But in case you need a toy to play with - here we go:

Syntax is quite easy, it's just <option> = <value>. Available options are:

managed_menusWhich menus should be maintained by the plugin.mainnav,metanav
serve_ui_filesWhether the required UI files (i.e. *.js and *.css files) should be linked into the page. Boolean value.1

The serve_ui_files option you will only need to override if you want to apply your own styles and need to suppress the original ones for this. Rare case - but who knows?


Demo config:

tracmenus.* = enabled

# Create a new top-level element for "Team Tools" - make sure to set it to "enabled" or it doesn't show up!
teamtools = enabled
teamtools.parent = top
teamtools.label  = Team Tools
# Do not display this menu if it has no children (e.g. visitor has no permission to any)
teamtools.hide_if_no_children = 1
# Now add the discussion plugin here
discussion = enabled
discussion.parent = teamtools
# Add the worklog here as well
worklog.parent = teamtools

# Add more things...

# rename "Browse Source" to "Code"
browser.label = Code
# Add some entry points to the code browser
code_trunk = enabled

# this is no component - so to hide it if not available, we need a trick
code_trunk.perm = BROWSER_VIEW

# Add some reports to the ticket item
special_report = enabled
special_report.label=My Tickets
# same trick as above required here

# Some more things

# unassigned is a reserved keyword:
# - if present, all other items not specified in config section will appear as sub-items under unassigned item. 
# - if not present, all other items will appear as top items.
unassigned = enabled

# Make sure the Wiki is always the first item - and Admin always the last:
wiki.order = -999999
admin.order = 999999


Recent Changes

17159 by rjollos on 2018-04-25 00:29:34
TracMenusPlugin 0.3.0dev: Improve layout of menu items

Patch by DG1000s.

Fixes #13353, Refs #13018, #11727.

17158 by rjollos on 2018-04-25 00:22:56
TracMenusPlugin 0.3.0dev: Conform to PEP8
16734 by rjollos on 2017-08-21 09:09:33
TracMenusPlugin 0.2.0: Restore missing styles

Fixes #13018, #11727.



Author: cbalan
Contributors: izzy

Attachments (1)

Download all attachments as: .zip