[Zope3-Users] Zope 3 and menus

Tom Gross tom at lalisio.com
Tue Mar 13 10:12:13 EDT 2007


Hi there,

    I override BrowserMenu from zope.app.publisher.browser.menu and add 
a entry 'abs_action' to the resulting dictionary.

Something like:

class MyBrowserMenu(BrowserMenu):

    def modify(self, menu, request):
        siteurl = absoluteURL(hooks.getSite(), request)
        for item in menu:
            item['abs_action'] = siteurl + '/' + item['action']
	submenu = item.get('submenu', None)
        if submenu is not None:
            self.modify(submenu, request)

    def getMenuItems(self, obj, request):
        menu = super(MyBrowserMenu, self).getMenuItems(obj, request)
	self.modify(menu, request)
        return menu


 <browser:menu
      id="monitor_menu"
      title="menu description here"
      class=".MyBrowserMenu"
      />


<div id="monitor_menu" class="box">
    <ul>
        <li tal:repeat="item context/@@view_get_menu/monitor_menu">
            <a href=""
                tal:attributes="href item/abs_action; title item/description"
                tal:content="item/title"></a>
        </li>
    </ul>    
</div>

Cheers
-Tom

eXt wrote:
> Hi
>
> 	I've got a problem with menus. I'd like to define a global menu, and then add 
> some options to it depending on actual context (view registered for specific 
> interface). The problem is that when I define global menu element link like: 
> action="/index.html" it generates url which omits my folder structure which 
> shold be: root/my_site/index.html  and creates: root/index.html. On the other 
> side when i use: action="index.html" the url which is created is always 
> relative. I'd like to be able to define my_site (which is in fact a Site 
> object) to be root for actions.
>
> What is the correct solution for that? Should I edit global urls before 
> displaying them (add my_site part)? Look at third code snippet below - it 
> generates urls so I can easly change some strings. Is this a proper solution?
>
> My code:
>
> Menu definition:
>
>  <browser:menu
>       id="monitor_menu"
>       title="menu description here"
>   />
>
> Global menu action (snippet from worldcookery.com code):
>
>   <browser:menuItem
>       for="*"
>       menu="monitor_menu"
>       title="Start"
>       action="/index.html"
>       permission="zope.View"
>   />
>
> Context dependent action:
>
> <browser:page
>       name="edit.html"
>       for="..interfaces.IMonitorConfDB"
>       class=".monitor_conf_db_view.MonitorConfDBEditForm"
>       permission="zope.View"
>       menu="monitor_menu"
>       title="Edit config"
>       />
>
> I display menu using viewlet with template (iirc code from worldcookery book):
>
> <div id="monitor_menu" class="box">
>     <ul>
>         <li tal:repeat="item context/@@view_get_menu/monitor_menu">
>             <a href=""
>                 tal:attributes="href item/action; title item/description"
>                 tal:content="item/title"></a>
>         </li>
>     </ul>    
> </div>
>
>
>   



More information about the Zope3-users mailing list