Django template tags to add active class on navigation menus
- Django 4.2
- Python 3.10
From sources
python setup.py install
From PyPi
pip install django-navhelper==1.0
Add geelweb.django.navhelper
in your INSTALLED_APPS
.
Returns "active" if url name of the current request path is in the list of view names
{% load navactive %}
<li class="{% navactive request "view_name app_name:another_view_name namespace:" %}">
<a href="{% url "view_name" }">Menu Entry</a>
</li>
Returns "active" if the pattern is found in the request path
{% load navactive %}
<li class="{% renavactive request "^/start_with_foo" %}">
<a href="{% url "view_name" }">Menu Entry</a>
</li>
You can customize some options using settings
NAVHELPER_ACTIVE_CLASS
Default: 'active'
The class name for active entries
NAVHELPER_NOT_ACTIVE_CLASS
Default: '' (Empty string)
The class name for non-active entries
To run the test suite, first, create and activate a virtual environment. Then install some requirements and run the tests:
pip install Django==4.2
python runtests.py