据了解,MENU
助手可以通过两种方式指示当前菜单项,并为该项web2py-menu-active
添加<li>
类。对每个菜单项的第二项使用表达式是一种非常手动的千篇一律的方法,涉及大量的剪切和粘贴。
因此,提供active_url
参数更具代码效率。
显然the way to get the current URL in web2py has already been answered但我想确认下面的代码是理想的代码,用于告知MENU
哪个菜单项要追加web2py-menu-active
:
MENU( ...., active_url=URL(args=request.args, vars=request.get_vars, host=True))
答案 0 :(得分:1)
这有效:
{{=MENU(response.menu,
_class='nav navbar-nav', li_class='dropdown',
ul_class='dropdown-menu', active_url=request.url)}}