Просмотр исходного кода

Use NavigationLink for topnav items

Peter Justin 3 лет назад
Родитель
Сommit
ef97f04230
2 измененных файлов с 39 добавлено и 5 удалено
  1. 11 0
      flaskbb/templates/_macros/navigation.html
  2. 28 5
      flaskbb/templates/layout.html

+ 11 - 0
flaskbb/templates/_macros/navigation.html

@@ -14,6 +14,17 @@
 {% endmacro %}
 
 
+{% macro topnavitems(items) %}
+{% for item in items %}
+    {% if item.content_type == NavigationContentType.link %}
+    {{ topnav(item.endpoint, item.name, item.icon, '', item.active) }}
+    {% else %}
+    {# skip unsupported types #}
+    {% endif %}
+{% endfor %}
+{% endmacro %}
+
+
 {% macro navlink(endpoint, name, icon='', active='', urlforkwargs=None) %}
 <li class="nav-item">
     <a class="nav-link {{ is_active(endpoint, active) }}" href="{% if urlforkwargs %}{{ url_for(endpoint, **urlforkwargs) }}{% else %}{{ url_for(endpoint) }}{% endif %}">

+ 28 - 5
flaskbb/templates/layout.html

@@ -62,17 +62,34 @@
                     </button>
                     <div class="collapse navbar-collapse" id="navbarNavDropdown">
                         <ul class="navbar-nav me-auto">
-                            {%- from theme("_macros/navigation.html") import is_active, topnav with context -%}
+                            {%- from theme("_macros/navigation.html") import is_active, topnavitems, topnav with context -%}
+
+                            {{ topnavitems(
+                                run_hook(
+                                    "flaskbb_tpl_navigation_before",
+                                    is_markup=False
+                                ))
+                            }}
 
-                            {{ run_hook("flaskbb_tpl_navigation_before") }}
                             {{ topnav(endpoint='forum.index', name=_('Forum'), icon='far fa-comment', active=active_forum_nav) }}
                             {{ topnav(endpoint='forum.memberlist', name=_('Memberlist'), icon='far fa-user') }}
                             {{ topnav(endpoint='forum.search', name=_('Search'), icon='fas fa-search') }}
-                            {{ run_hook("flaskbb_tpl_navigation_after") }}
+
+                            {{ topnavitems(
+                                run_hook(
+                                    "flaskbb_tpl_navigation_after",
+                                    is_markup=False
+                                ))
+                            }}
                         </ul>
 
                         <ul class="navbar-nav">
-                            {{ run_hook("flaskbb_tpl_user_nav_loggedin_before") }}
+                            {{ topnavitems(
+                                run_hook(
+                                    "flaskbb_tpl_user_nav_loggedin_before",
+                                    is_markup=False
+                                ))
+                            }}
 
                             {% if current_user and current_user.is_authenticated %}
                             <!-- User Menu -->
@@ -121,7 +138,13 @@
                                     </ul>
                                 </div>
                             </li>
-                            {{ run_hook("flaskbb_tpl_user_nav_loggedin_after") }}
+                            {{ topnavitems(
+                                run_hook(
+                                    "flaskbb_tpl_user_nav_loggedin_after",
+                                    user=current_user,
+                                    is_markup=False
+                                ))
+                            }}
 
                             {% else %}
                             <!-- Not logged in - Login/Register -->