Skip to content

Instantly share code, notes, and snippets.

@ulmus
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ulmus/7056bad51b7d1099fe93 to your computer and use it in GitHub Desktop.
Save ulmus/7056bad51b7d1099fe93 to your computer and use it in GitHub Desktop.
A basic way of implementing a static navbar in django with the current page marked as active
<ul class="navbar">
{% for item in navbar %}
<li {% if item.name==active_navigation%}class="active"{% endif %}><a href="{{item.url}}">{{item.label}}</a></li>
{% endfor %}
</ul>
<body>
{% include "navbar.html" %}
</body>
NAVBAR = [
{"name":"main", "label":"Main Page", "url":"/"},
{"name":"games", "label":"Game Page", "url":"/games/"},
]
def main_view_with_navbar(request):
# Lots of view functionality
return render("path/to/template.html", dictionary={
"navbar" : NAVBAR,
"active_navigation" : "main"
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment