Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

highlight active nav item #115

Open
wants to merge 1 commit into
base: stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions dolweb/blog/templatetags/blog_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from bs4 import BeautifulSoup
from django.conf import settings
from django.template import defaultfilters
from django.urls import reverse
from dolweb.blog.models import BlogSeries

@register.inclusion_tag('blog_chunk_series.html')
Expand All @@ -24,3 +25,10 @@ def cuthere_excerpt(content):
return ''.join(map(str, reversed(cut_here.parent.find_previous_siblings())))
except AttributeError:
return defaultfilters.truncatewords(content, 100)


@register.simple_tag
def navactive(request, urls):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im willing to define this tag in a more central location but i couldn't find a suitable one; let me know if there's a better spot for this!

if request.path in ( reverse(url) for url in urls.split() ):
return "active"
return ""
37 changes: 28 additions & 9 deletions dolweb/templates/_base.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% load i18n %}
{% load language %}
{% load static from staticfiles %}
{% load blog_tags %}

<!DOCTYPE html>

Expand Down Expand Up @@ -103,15 +104,33 @@
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav pull-left">
<li><a href="{% url 'downloads_index' %}">{% trans "Download" %}</a></li>
<li><a href="{% url 'zinnia:entry_archive_index' %}">{% trans "Blog" %}</a></li>
<li><a href="{% url 'media_all' %}">{% trans "Screenshots" %}</a></li>
<li><a href="{% url 'docs_faq' %}">{% trans "FAQ" %}</a></li>
<li><a href="{% url 'docs_guides_index' %}">{% trans "Guides" %}</a></li>
<li><a href="{% url 'compat_index' %}">{% trans "Compatibility" %}</a></li>
<li><a href="{{ FORUM_URL }}">{% trans "Forum" %}</a></li>
<li><a href="{{ WIKI_URL }}">{% trans "Wiki" %}</a></li>
<li><a href="{{ GIT_BROWSE_URL }}">{% trans "Code" %}</a></li>
<li class="{% navactive request 'downloads_index' %}">
<a href="{% url 'downloads_index' %}">{% trans "Download" %}</a>
</li>
<li class="{% navactive request 'zinnia:entry_archive_index' %}">
<a href="{% url 'zinnia:entry_archive_index' %}">{% trans "Blog" %}</a>
</li>
<li class="{% navactive request 'media_all' %}">
<a href="{% url 'media_all' %}">{% trans "Screenshots" %}</a>
</li>
<li class="{% navactive request 'docs_faq' %}">
<a href="{% url 'docs_faq' %}">{% trans "FAQ" %}</a>
</li>
<li class="{% navactive request 'docs_guides_index' %}">
<a href="{% url 'docs_guides_index' %}">{% trans "Guides" %}</a>
</li>
<li class="{% navactive request 'compat_index' %}">
<a href="{% url 'compat_index' %}">{% trans "Compatibility" %}</a>
</li>
<li>
<a href="{{ FORUM_URL }}">{% trans "Forum" %}</a>
</li>
<li>
<a href="{{ WIKI_URL }}">{% trans "Wiki" %}</a>
</li>
<li>
<a href="{{ GIT_BROWSE_URL }}">{% trans "Code" %}</a>
</li>
</ul>
<ul class="nav navbar-nav pull-right">
<li class="dropdown">
Expand Down