You can use this to render the menu, just put the function in a model (or 
in a module and import it in the model) and replace line 43-60 of 
layout.html with {{=BS4MENU(response.menu)}}

It changes your LI(_class='divider') to LI(_class='dropdown-divider') to 
work with BS4

def BS4MENU(data, id_prefix='main'):
    """
    Used to build menus
    """
    from gluon.html import XmlComponent
    ul = UL(_class='navbar-nav')
    for i, item in enumerate(data):
        (name, active, link) = item[:3]
        if link:
            li = LI(A(name, _href=link, _class='nav-link', _id=
'%s-menu-link-%d' % (id_prefix, i)), _class='nav-item')
        else:
            li = LI(A(name, _href='#', _class='nav-link', _id=
'%s-menu-link-%d' % (id_prefix, i)), _class='nav-item')
        if len(item) > 3 and item[3]:
            li['_class'] += ' dropdown'
            a = li[0]
            a['_class'] += ' dropdown-toggle'
            a['_data-toggle'] = 'dropdown'
            a['_role'] = 'button'
            a['_aria-haspopup'] = 'true'
            a['_aria_expanded'] = 'false'
            div = DIV(_class='dropdown-menu dropdown-menu-right')
            div['_aria-labelledby'] = '%s-menu-link-%d' % (id_prefix, i)
            for j, subitem in enumerate(item[3]):
                if isinstance(subitem, XmlComponent):
                    if '_class' in subitem and 'divider' in subitem['_class'
]:
                        div.append(DIV(_class='dropdown-divider'))
                    continue
                
                (name, active, link) = subitem[:3]
                if link:
                    a = A(name, _href=link, _class='dropdown-item', _id=
'%s-menu-link-%d-%d' % (id_prefix, i, j))
                else:
                    a = A(name, _href='#', _class='dropdown-item', _id=
'%s-menu-link-%d-%d' % (id_prefix, i, j))
                if active:
                    a['_class'] + ' active'
                div.append(a)
            li.append(div)

        if active:
          li['_class'] += ' active' 
        ul.append(li)
    return ul



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to