The {% navlink %} tag provides a convenient way to create navigation links that automatically change based on the active navigation state. It works as a block tag that renders different HTML elements depending on whether the navigation item is active.
The {% navlink %} tag supports special patterns for more precise matching:
Children-only pattern (item!):
{%nav"courses.special"%}{%navlink'courses''course_list'%}All Courses{%endnavlink%}{# Renders as link with class="active" #}{%navlink'courses!''course_detail'%}Course Details{%endnavlink%}{# Renders as link with class="active" - only when nav is a child of courses #}
When courses is active (not a child), the first link is active but the second becomes a <span>.
Exclusion pattern (item!exclude):
{%nav"courses.special"%}{%navlink'courses!list''course_detail'%}Course (not list){%endnavlink%}{# Renders as link - active for any child except 'list' #}{%navlink'courses!special''course_detail'%}Course (not special){%endnavlink%}{# Renders as span - 'special' is excluded #}
You can also use these patterns with {% if %} statements:
{%ifnav=="courses!"%}{# True - matches any child of courses #}{%endif%}
Alternate nav context
To use a different navigation context variable, prefix the nav item with the variable name:
Data provided by the project maintainers, verified at the time the release was uploaded to PyPI. Confirms that the provided email matches a verified, public email address on a PyPI user account associated with the project.
Data provided by the project maintainers, verified at the time the release was uploaded to PyPI. Confirms that the provided email matches a verified, public email address on a PyPI user account associated with the project.