Skip to content
Snippets Groups Projects
Verified Commit 496a07cf authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Add support for (dynamic) menu item badges

parent aef9fc72
No related branches found
No related tags found
1 merge request!447Resolve "Add own menu entry for notifications"
......@@ -136,9 +136,8 @@ ul.sidenav li.logo > a:hover {
background-color: lighten($primary-color, 5%);
}
li.active > a > .sidenav-badge {
background-color: whitesmoke !important;
color: $primary-color !important;
.sidenav-badge {
min-width: 2rem!important;
}
.sidenav li.search {
......
{# -*- engine:django -*- #}
{% load menu_generator %}
{% load menu_generator data_helpers %}
{% get_menu "NAV_MENU_CORE" as core_menu %}
......@@ -16,6 +16,10 @@
<i class="material-icons">{{ item.icon }}</i>
{% endif %}
{{ item.name }}
{% build_badge item as badge %}
{% if badge %}
<span class="new badge sidenav-badge"> {{ badge }}</span>
{% endif %}
</a>
</li>
{% endif %}
......@@ -28,6 +32,10 @@
<i class="material-icons">{{ item.icon }}</i>
{% endif %}
{{ item.name }}
{% build_badge item as badge %}
{% if badge %}
<span class="new badge sidenav-badge"> {{ badge }}</span>
{% endif %}
</a>
<div class="collapsible-body">
<ul>
......@@ -40,6 +48,10 @@
<i class="material-icons">{{ menu.icon }}</i>
{% endif %}
{{ menu.name }}
{% build_badge item as badge %}
{% if badge %}
<span class="new badge sidenav-badge"> {{ badge }}</span>
{% endif %}
</a>
</li>
{% endfor %}
......
......@@ -51,3 +51,14 @@ def parse_json(value: Optional[str] = None) -> Union[dict, None]:
if not value:
return None
return json.loads(value)
@register.simple_tag(takes_context=True)
def build_badge(context: dict, item: dict) -> Any:
"""Get menu badge content from django-menu-generator dict."""
request = context["request"]
badge = item.get("badge")
if callable(badge):
return badge(request)
else:
return badge
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment