Last active
October 12, 2015 16:58
-
-
Save elyezer/4058848 to your computer and use it in GitHub Desktop.
Django template tag to add active class in navigation links
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
{% load navigation %} | |
<!-- Specific path, only when visiting /accounts/ --> | |
<li class="{% active request "^/accounts/$" %}"><a href="/accounts/">Accounts</a></li> | |
<!-- Glob path, when visiting /blog/* example /blog/, /blog/post1/, /blog/post2/, /blog/post2/subitem/, ... --> | |
<li class="{% active request "^/blog/" %}"><a href="/blog/">Blog</a></li> |
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
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS | |
# Other settings... | |
TEMPLATE_CONTEXT_PROCESSORS += ( | |
'django.core.context_processors.request', | |
) | |
# Other settings... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment