Skip to main content

A simple Django navigation template tag

Project description

A simple Django template tag to handle navigation item selection.

Example

Add the app to your INSTALLED_APPS setting:

INSTALLED_APPS = (
        # ...
        'django_navtag',
)

Give your base template a navigation block something like this:

{% block nav %}
<ul class="nav">
    <li{% if nav.home %} class="selected"{% endif %}>
        <a href="/">Home</a>
    </li>
    <li{% if nav.about %} class="selected"{% endif %}>
        <a href="/about/">About</a>
    </li>
</ul>
{% endblock %}

In your templates, extend the base and set the navigation location:

{% extends "base.html" %}

{% block nav %}
{% nav "home" %}
{{ block.super }}
{% endblock %}

Hierarchical navigation

To create a sub-menu you can check against, simply dot-separate the item:

{% nav "about_menu.info" %}

This will be pass for both {% if nav.about_menu %} and {% if nav.about_menu.info %}.

Using a different context variable

By default, this tag creates a nav context variable. To use an alternate context variable name, call {% nav [item] for [var_name] %}:

{% block nav %}
{% nav "home" for sidenav %}
{{ block.super }}
{% endblock %}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-navtag-1.1.tar.gz (5.7 kB view details)

Uploaded Source

File details

Details for the file django-navtag-1.1.tar.gz.

File metadata

  • Download URL: django-navtag-1.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for django-navtag-1.1.tar.gz
Algorithm Hash digest
SHA256 ef175cbcc8890b69c0f453febf2f69e8b121fca54fca05da6a38617c7a4ef094
MD5 7fc48fd5125a2b84a22d99fdc7987f48
BLAKE2b-256 f4e67e64cf166c2e1124242d0857da0f392e5fec28b23a000b49a0052cbb363f

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page