开发者

Highlight current menu item lift

H开发者_JAVA百科ow can I determine the page I am currently on in Lift?

In django, for example, in my base template I had simple checks like these:

<li {% ifequal main_navigation "home" %} class="selected"{%endifequal%}>
    <a href="{% url home %}">Home</a>
</li>
<li {% ifequal main_navigation "risk"%}class="selected"{%endifequal%}>
    <a href="{% url risk %}">Risk</a>
</li>

<li {% ifequal main_navigation "contact" %}class="selected"{%endifequal%}>
    <a href="{% url contact %}">Contact</a>
</li>

here, the if determines what the context variable main_navigation is set to.


I'm assuming you're using the sitemap for your menu.

When rendering the menu with the Menu.builder snippet you can use additional parameters to further tweak the menu. This example will render only the first level of the menu and adds class current to the menu item if it's the current page.

designer friendly example:

<div class="lift:Menu.builder?level=0;expand=false;li_item:class=current"></div>

or

<lift:Menu.builder  li_item:class="selected" level="0" expand="false" />

for more details see the lift wiki: http://www.assembla.com/wiki/show/liftweb/SiteMap


If you use Lift's SiteMap and Menu functionality, I think this is taken care of automatically. You can read about it here: http://simply.liftweb.net/index-3.2.html#toc-Subsection-3.2

To answer your broader question, within a Snippet (not a template), you can use LiftRules.context, which returns an HTTPContext including a path attribute.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜