Active link

 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

  1. Active page class for selected menu items by kunitoki 7 months, 4 weeks ago
  2. template tag for highlighting currently active page by adunar 4 years, 7 months ago
  3. Active class for navigation link by cschand 3 years, 8 months ago
  4. Pagination Alphabetically compatible with paginator_class by vascop 1 year, 1 month ago
  5. Multi-level (tree-ish) navigation by jpic 4 years, 7 months ago

Comments

(Forgotten your password?)