I'm not sure there's an easy way. The MENU() helper doesn't generate the
nested UL/LI's until it is actually serialized in the view, so using the
server-side DOM is tricky. You can force the serialization and then convert
back to a nested helper object using TAG as follows:
menu = TAG(MENU(response.menu).xml())
I'm not sure how you want to assign unique ID's to each link, but you could
then do something like:
[li.update(_id='link' + num) for num, li in enumerate(menu.elements('li'))]
menu.elements('li') returns a list of all the LI elements in the menu, and
the rest of the code adds id's of the form "link1", "link2", etc.. If you
only want LI's within sub-menus, you could instead do:
menu.elements('.web2py-expand-menu ul li')
though if you have multiple levels of sub-menus, that will also include the
lower level sub-menu labels.
Another approach is with response.menu itself. Items in the menu can be
LI() elements rather than tuples, so you can define your own custom LI's.
For example, instead of:
response.menu = [(T('Home'), False, URL('default', 'index'))]
you could do:
response.menu = [LI(A('Home', _href=URL('default', 'index')), _id='myid')]
Of course, that is only helpful when limited to the last sub-menu level
(doing so at a higher level in the menu hierarchy means you have to
manually build the entire lower level of the hierarchy because you lose the
ability to nest via tuples).
Another option that may work for you would be to add the id's to the A()
elements rather than the LI() elements. The easiest way to do this is to
make the third element in the menu item tuple a dictionary of the A()
attributes rather than just the URL. For example:
response.menu = [(T('Home'), False, dict(_href=URL('default', 'index'),
_id='myid'))]
You'll then get a menu item like:
<li><a href='/myapp/default/index' id='myid'>Home</a></li>
Anthony
On Thursday, April 11, 2013 9:17:14 AM UTC-4, at wrote:
>
> Hello,
>
> Is it possible to define ids of <li>s if we are using MENU helper /
> response.menu?
>
>
>
> On Thursday, 11 April 2013 14:47:00 UTC+5, at wrote:
>>
>>
>> Can somebody assist how can we define "id"s for sub-menu items?
>>
>> Thanks
>>
>>
--
---
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/groups/opt_out.