1๐
โ
You should do this kind of thing with template inheritance. For example, your base.html
might include a navigation list with:
<li{% block products %}{% endblock %}><a href...>Products</a></li>
<li{% block about %}{% endblock %}><a href...>About</a></li>
Then in your about
template (assuming it inherits from base
) you have:
{% block about %} class="active"{% endblock %}
This will render as pure html, using the class you have defined for active pages. Because it uses simple template inheritance you can also get really fine control with this.
๐คcms_mgr
1๐
I use my own template tag called ifnav
.
- http://pypi.python.org/pypi/django-ifnav-templatetag
- https://bitbucket.org/bikeshedder/django-ifnav-templatetag
The usage is very simple. Just add it to your INSTALLED_APPS
and make sure the request context processor is activated.
Afterwards you can write this:
<li {% ifnav "^/about/" %} class="active" {% endifnav %}><a href="{% url about_project %}"> About</a></li>
For current projects I use Django CMS which takes care of rendering the navigation.
๐คbikeshedder
- [Answered ]-'Page' object has no attribute 'ordered' Exception
- [Answered ]-How do I properly specify arguments to display a method's output in Django admin?
- [Answered ]-Are django models thread safe?
- [Answered ]-Building a webapp to serve multiple HG repositories
Source:stackexchange.com