Snippet List
Simple tag to check which page we are on, based on resolve: useful to add an 'active' css class in menu items that needs to be aware when they are selected.
Typical usage is like:
`
<ul>
<li class="{% active request "myapp:myview1" %}">My View 1</li>
<li class="{% active request "myapp:myview2" %}">My View 2</li>
</ul>
`
This is the description of a custom template tag to create DRY menu. It solves the problem of markup duplication in templates of your site. The menu always has one active option and one or several inactive options.
HOW TO USE
Define a structure of your menu in a parent template:
{% defmenu "menu1" %}
{% active %}<span class='active'>__text__</span>{% endactive %}
{% inactive %}<a href='__url__'>__text__</a>{% endinactive %}
{% opt "opt1" "/opt1/" %}Go to opt1{% endopt %}
{% opt "opt2" "/opt2/" %}Go to opt2{% endopt %}
{% opt "opt3" "/opt3/" %}Go to opt3{% endopt %}
{% enddefmenu %}
The menu has it's name (first parameter of the tag 'defmenu'.
First parameter of a tag 'opt' is menu option's name. '__text__' inside of 'active'/'inactive' will be substituted by inner text of a tag 'opt' (Go to opt...), '__url__' indide of 'active'/'inactive' will be substituted by second parameter of a tag 'opt'
To generate menu with one selected option in child template do:
{% menu "menu1" "opt1" %}
Here: "menu1" is a name of menu that was defined by 'defmenu' tag, "opt1" is selected option.
Result of the applying 'menu' is the next:
<span class='active'> Go to opt1</span> <a href='"/opt2/"'>Go to opt2</a> <a href='"/opt3/"'>Go to opt3</a>
An old snippet I made in my first django project. Nowadays I code menus in HTML and just use the perms proxy: https://docs.djangoproject.com/en/1.0/topics/auth/#id6
Credits, (awsome persons that helped me getting it to work efficiently and for free):
* Yhg1s and waveform from #python@freenode
* zendak from #django@freenode
Thank you!
- menu
- navigation
- menubar
- navbar
This tag makes it easy to include menu or navigation bars in an application's pages, even in a 'tabbed' fashion. (The actual appearance is styled in CSS; this example uses UL tags that are then supposed to be styled by a "display: inline" attribute to be rendered as horizontal bars.)
- tag
- menu
- navigation
- menubar
- navbar
8 snippets posted so far.