Skip to main content

A simple Django navigation template tag

Project description

A simple Django template tag to handle navigation item selection.

https://secure.travis-ci.org/SmileyChris/django-navtag.png?branch=master

Example

Add the app to your INSTALLED_APPS setting:

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

Give your base template a navigation block something like this:

{% load navtag %}

{% block nav %}
{% nav text ' class="selected"' %}
<ul class="nav">
    <li{{ nav.home }}><a href="/">Home</a></li>
    <li{{ nav.about }}><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 %}

Setting the text output by the nav variable

As shown in the initial example, you can set the text return value of the nav context variable. Use the format {% nav text [content] %}. For example:

{% nav text "active" %}
<ul>
<li class="{{ nav.home }}">Home</li>
<li class="{{ nav.contact }}">Contact</li>
</ul>

Alternately, you can use boolean comparison of the context variable rather than text value:

<section{% if nav.home %} class="wide"{% endif %}>

If using a different context variable name, use the format {% nav text [content] for [var_name] %}.

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-2.1.3.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

django_navtag-2.1.3-py2.py3-none-any.whl (10.9 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

File hashes

Hashes for django-navtag-2.1.3.tar.gz
Algorithm Hash digest
SHA256 b188ddb696a1212f568ad53b436a5762c6a294dd052a14ecb73fdcfcfc6d6bb8
MD5 6fe6e7c5721d0cd66114271b488f159f
BLAKE2b-256 164b174c0232f03f84e4de67979b179caf76f0eeb8dd4717ee54906c2060f814

See more details on using hashes here.

Provenance

File details

Details for the file django_navtag-2.1.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_navtag-2.1.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 22976b29d7757f8d67c162f5b86baeeafbbf765bcb466862427f0d21b709acc2
MD5 0ec200d8c85c96cc7b5e84c3daaaa073
BLAKE2b-256 06669d2e9a63b7a6384261042b9f784c8d2213a1edb62548b913b93981e9a548

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