The best way to highlight active links in your Django app.
Project description
The simplest way to highlight active links in your Django app.
Documentation
The full documentation is at https://django-active-link.readthedocs.io.
Quick start
Install Django Active Link:
pip install django-active-link
Add it to your INSTALLED_APPS:
INSTALLED_APPS = (
...
'active_link',
...
)
To use the active_link template tag you need to load active_link_tags templatetags library:
{% load active_link_tags %}
To add an active CSS class to a link when the request path matches a given view just do something like this.
<a href="{% url 'view-name' %}" class="{% active_link 'view-name' %}">Menu item</a>
If you has a sub-menu or tabs and needs they be active and parent too, you can use || to check this:
<a href="{% url 'view-name' %}" class="{% active_link 'view-name || view-sub-name' %}">Menu Item</a>
<a href="{% url 'view-sub-name' %}" class="{% active_link 'view-sub-name' %}">Tab Item</a>
You can also use a custom CSS class:
<a href="{% url 'view-name' %}" class="{% active_link 'view-name' 'custom-class' %}">Menu item</a>
or:
<a href="{% url 'view-name' %}" class="{% active_link 'view-name' css_class='custom-class' %}">Menu item</a>
By default active_link will not perform a strict match. If you want to add the active class only in case of a strict match pass the strict argument to the tag:
<a href="{% url 'view-name' %}" class="{% active_link strict=True %}">Menu item</a>
Replace view-name with the name of your view (including namespaces).
Settings
You can override the default active class and strict mode with the settings ACTIVE_LINK_CSS_CLASS and ACTIVE_LINK_STRICT.
Key |
Description |
Default Value |
---|---|---|
ACTIVE_LINK_CSS_CLASS |
Active class to use. |
active |
ACTIVE_LINK_STRICT |
Designates whether to perform a strict match or not. |
False |
For more usage examples, please check the full documentation at https://django-active-link.readthedocs.io.
IMPORTANT: Django Active Link requires that the current request object is available in your template’s context. This means you must be using a RequestContext when rendering your template, and django.core.context_processors.request must be in your TEMPLATE_CONTEXT_PROCESSORS setting. See https://docs.djangoproject.com/en/dev/ref/templates/api/#subclassing-context-requestcontext for more information.
TODO
Write the documentation
Running Tests
Does the code actually work?
source <YOURVIRTUALENV>/bin/activate (myenv) $ pip install tox (myenv) $ tox
Credits
Tools used in rendering this package:
History
0.1.0 (2017-07-10)
First release on PyPI.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_active_link-0.1.5-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7c7eaad645275b8833e235e17a0b54a129af9eb2b1a9a398e9cb96b40a15218 |
|
MD5 | f31c1f4a79635d1a59cc4ecfa7b1d967 |
|
BLAKE2b-256 | c9a866f44de688888c2b584dd30403af56be97aa338a98fe8e66a7fd5b5995ad |