Created
September 21, 2011 08:44
-
-
Save zhangsen/1231597 to your computer and use it in GitHub Desktop.
django-navigation-highlight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### tag #### | |
from django import template | |
from django.core import urlresolvers | |
register = template.Library() | |
@register.simple_tag | |
def nav_active(request, views): | |
views = ["myapp.views." + view for view in views.split()] | |
try: | |
view = urlresolvers.resolve(request.path).url_name | |
if view in views: | |
return "active" | |
else: | |
return "" | |
except urlresolvers.Resolver404: | |
return "" | |
#### template #### | |
<div class="mainnavs"> | |
<ul> | |
<li class="{% nav_active request 'index new_event event_detail edit_event edit_event_label' %}"> | |
<a href="/">Events</a> | |
</li> | |
<li class="{% nav_active request 'all_labels events_by_label' %}"> | |
<a href="/labels/">Labels</a> | |
</li> | |
<li class="{% nav_active request 'all_articles articles_by_domain' %}"> | |
<a href="/articles/">Articles</a> | |
</li> | |
<li class="{% nav_active request 'user users' %}"> | |
<a href="/users/">Users</a> | |
</li> | |
</ul> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment