Git Product home page Git Product logo

django-active-link's Introduction

Django Active Link

Updates https://travis-ci.org/valerymelou/django-active-link.svg?branch=master

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>

You can even add the active class when the request path matches multiple views. Just pass the view names separated by a double pipe (||) as first argument to the active_link tag.

<a href="{% url 'view-name' %}" class="{% active_link 'view-name || view-sub-name' %}">Menu 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>

You can also define an inactive custom css class, that is triggered when a link is deemed not active:

<a href="{% url 'view-name' %}" class="{% active_link 'view-name' 'custom-class' 'not-active' %}">Menu item</a>

or:

<a href="{% url 'view-name' %}" class="{% active_link 'view-name' css_class='custom-class' css_inactive_class='not-active' %}">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, ACTIVE_LINK_CSS_INACTIVE_CLASS and ACTIVE_LINK_STRICT.

Key Description Default Value
ACTIVE_LINK_CSS_CLASS Active class to use. active
ACTIVE_LINK_CSS_INACTIVE_CLASS Inactive class to use. ย 
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.template.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
  • Clean repository for unneccesary files

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install poetry
(myenv) $ poetry install --only test
(myenv) $ poetry run tox

Credits

Tools used in rendering this package:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.