Skip to content

Instantly share code, notes, and snippets.

@rochacbruno
Created June 30, 2011 05:33
Show Gist options
  • Select an option

  • Save rochacbruno/1055688 to your computer and use it in GitHub Desktop.

Select an option

Save rochacbruno/1055688 to your computer and use it in GitHub Desktop.
Menu with toggle classes for selected links
def index():
return dict()
def contact():
return dict()
# Pages is a list of tuples, each tuple has 3 values: URL(), Text, FunctionName
pages = [
(URL('default','index'),"Home","index"), # points to default.py/def index():
(URL('default','contact'),"Contact us","contact"), # points to default.py/def contact():
]
#this is just appended if user is logged in
if auth.user:
pages.append((URL('default','user',args='profile'),"Profile","user"))
pages.append((URL('default','user',args='change_password'),"Password","user"))
pages.append((URL('default','user',args='logout'),"Exit","user"))
# the menu builder
def menu():
ul = UL()
for page in pages:
liclass = "selected" if request.function == page[2] else ""
if page[2] == "index": liclass = ""
ul.append(LI(A(page[1],_href=page[0],_class=liclass)))
return ul
<html>
<head></head>
<body>
<section>
<nav>
{{block menu}}
{{=menu()}}
{{end}}
</nav>
</section>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment