django-simple-menu icon indicating copy to clipboard operation
django-simple-menu copied to clipboard

How to use target="blank"

Open kikyo2006 opened this issue 8 years ago • 2 comments

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.

kikyo2006 avatar Feb 23 '17 07:02 kikyo2006

you can add an extra argument: Menu.add_item("main", MenuItem("Dashboard", '#', target='blank'))

progressify avatar Jan 09 '20 10:01 progressify

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 %}

kytta avatar May 08 '22 13:05 kytta