Skip to main content

A simple Django navigation template tag

Project description

https://badge.fury.io/py/django-navtag.svg https://travis-ci.org/SmileyChris/django-navtag.svg?branch=master https://codecov.io/gh/SmileyChris/django-navtag/branch/master/graph/badge.svg

A simple Django template tag to handle navigation item selection.

Usage

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

Uploaded Source

Built Distribution

django_navtag-3.0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django-navtag-3.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2

File hashes

Hashes for django-navtag-3.0.tar.gz
Algorithm Hash digest
SHA256 1455b51c047aa294294b1294489017ae5e9bafb4d4a6b6f7f9bda09f7fdfd785
MD5 a7520551b1ab38a07eed4bef62ac08f4
BLAKE2b-256 16966d0e2dfc5744d66e9d146cddd04adbcba3f5b8cf10cc6ae971976dae6dc8

See more details on using hashes here.

File details

Details for the file django_navtag-3.0-py3-none-any.whl.

File metadata

  • Download URL: django_navtag-3.0-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2

File hashes

Hashes for django_navtag-3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 981d577e471c83fb5ef984f9e2a28619c31c722d1f048d754d56bb386030c4e2
MD5 3ef99bd05000cba9e49ca9dc66de7377
BLAKE2b-256 82e1e7fbb0885396fc8ca2c5f048074be28bbc20aa1bae2e558f435489abdbd3

See more details on using hashes here.

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