[Zope3-Users] menus, menu items and actions
Jan-Wijbrand Kolman
jw at infrae.com
Tue May 31 11:25:37 EDT 2005
Hi,
I'm working an application that will have some sort of 'main menu' of actions,
that should always be available in the UI of this applications.
So, I register a menu:
<menu
id="foo_menu"
title="The Main Foo Menu"
/>
and a menu item for it:
<menuItem
title="Do Bar"
description="Do Bar In This Application"
for="*"
menu="foo_menu"
action="bar"
permission="zope.Public"
/>
When rendering the HTML for this menu, the menu item's action is basically used
as a relative URL (relative to the current location in e.g. a content object
tree).
However, what I would like is to point to a specific URL relative to my
application root - since 'bar' is a specific view on my app.root.
At the moment, I solved it by implementing a custom menu class, subclassing
BrowserMenu:
from zope.app.publisher.browser.menu import BrowserMenu
class FooMenu(BrowserMenu):
def getMenuItems(self, object, request):
items = super(FooMenu, self).getMenuItems(object, request)
base = 'http://baz.qux.com/' # the base URL will be the absolute url for
# my application root
for item in items:
item['action'] = '%s/%s' % (base, item['action'])
return items
And register my foo menu like so:
<menu
id="foo_menu"
title="The Main Foo Menu"
class="fooapplication.browser.menu.FooMenu"
/>
This does work, but feels a bit icky - although I cannot really say why. Is
there a better way to achieve this?
regards,
jw
--
Jan-Wijbrand Kolman
jw at infrae.com
More information about the Zope3-users
mailing list