1 2 3 4 5 6 7 8 9 10 11 12 13 | **Placed in templates/includes/tabs.html**
<ul class="tab-menu">
<li class="{% if active_tab == 'tab1' %} active{% endif %}"><a href="#">Tab 1</a></li>
<li class="{% if active_tab == 'tab2' %} active{% endif %}"><a href="#">Tab 2</a></li>
<li class="{% if active_tab == 'tab3' %} active{% endif %}"><a href="#">Tab 3</a></li>
</ul>
**Placed in your page template**
{% include "includes/tabs.html" with active_tab='tab1' %}
|
More like this
- Clear session data on login and logout by jb0t 5 years, 2 months ago
- DRY menu Custom Template Tag by sergzach 1 year, 2 months ago
- Use django-admin.py instead of manage.py by whiteinge 5 years ago
- Auto-documenting Django Models with Sphinx by Voightkampff 1 year, 9 months ago
- TaggedManager and TaggedQuerySet with chainable tagged() methods implemented with django-tagging by fish2000 3 years, 3 months ago
Comments
nice
#
Thanks for sharing. This was very helpful. Finally got my navigation working where it supports multiple/nested menu levels and shows which ones are active.
#
Thank you! When I created a snippet #2722 I did not take into account the option with of inclusion tag.
I think your solution is better.
My decision have only one plus (your have several ones). In case of #2722 inheritance is possible. Sometimes it is more convenient and conceptual than inclusion.
#
And one more plus in #2722. In your case if you want to mek whole fragment different (not only class attribute) you should write several times very similar code for each option. But I would like DRY menu.
#
Now I use your snippet instead of mine. Thanks a lot!
#
This is such a clean solution; thank you so much for taking the time to share this!
#