django-simple-menu
django-simple-menu copied to clipboard
How to use target="blank"
hi, i want to use target="blank" with simple menu. So how can i do it? I did read document but it doesn't help.
you can add an extra argument:
Menu.add_item("main", MenuItem("Dashboard", '#', target='blank'))
Since you need to create the templates yourself, you can just add it to your HTML file. Here's a basic example, in which all items will have the attribute:
{% for item in menu %}
<li>
<a href="{{ item.url }}" target="_blank">
{{ item.title }}
</a>
</li>
{% endfor %}
Alternatively, as @progressify mentioned, you can add a custom kwarg to the MenuItem
and then set the target programmatically:
# menus.py
Menu.add_item("main", MenuItem("Dashboard", '#', target='_blank'))
{# menu.html #}
{% for item in menu %}
<li>
<a href="{{ item.url }}" {% if item.target %}target="{{ item.target }}"{% endif %}>
{{ item.title }}
</a>
</li>
{% endfor %}