I needed a way to find if a menu items should be active. After searching the internet i found a few options*, but none of them did fit my needs, so i wrote my own:
- http://gnuvince.wordpress.com/2008/03/19/the-new-and-improved-active-tag/
- http://stackoverflow.com/questions/340888/navigation-in-django
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | import re
from django import template
from django.core.urlresolvers import get_resolver
register = template.Library()
@register.simple_tag
def current(request, view):
possible_results = get_resolver(None).reverse_dict.getlist(view)
if len(possible_results) != 0 and re.match(possible_results[0][1], request.path[1:]):
return 'current'
return ''
|
More like this
- Form field with fixed value by roam 1 week, 4 days ago
- New Snippet! by Antoliny0919 2 weeks, 3 days ago
- Add Toggle Switch Widget to Django Forms by OgliariNatan 3 months, 1 week ago
- get_object_or_none by azwdevops 6 months, 4 weeks ago
- Mask sensitive data from logger by agusmakmun 8 months, 3 weeks ago
Comments
Please login first before commenting.