GithubHelp home page GithubHelp logo

rogeriofalcone / django-navtag Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ipmb/django-navtag

0.0 2.0 0.0 78 KB

Keep that navigation logic in the presentation layer where it belongs.

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%

django-navtag's Introduction

{% nav %} tag

A simple Django template tag to handle navigation item selection.

image

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 %}

Note

This works for multiple levels of template inheritance, due to the fact that the tag only does anything if the nav context variable does not exist. So only the first {% nav %} call found will ever be processed.

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 %}

django-navtag's People

Contributors

smileychris avatar ipmb avatar

Watchers

James Cloos avatar Rogerio avatar

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.