Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use target="blank" #50

Open
kikyo2006 opened this issue Feb 23, 2017 · 2 comments
Open

How to use target="blank" #50

kikyo2006 opened this issue Feb 23, 2017 · 2 comments
Labels

Comments

@kikyo2006
Copy link

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.

@progressify
Copy link

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

@kytta kytta added the question label May 8, 2022
@kytta
Copy link
Member

kytta commented May 8, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants