{# Nav -- These macros are designed for building the primary navigation and user navigation. By default, the prime nav is generated by the nav system in the python. It is strongly recommended that any navigation links are added/removed using python, however if required, you can overide the prime navigation in your local template like so: -------------------------------------------------------------------------------- {%- import "macros/nav.html" as _nav -%} {% block prime_nav -%} {% macro prime_nav_list() %}
Links
Link 3
...
... {% endmacro %} {{ _nav.prime_nav(prime_nav_list()) }} {%- endblock %} -------------------------------------------------------------------------------- Taking this approach allows you to retain the prime nav container formatting but overwrite the inner list of nav items/links. The user nav component is very similar to the prime nav component in it's HTML/CSS construction but is not generated using python. By default, the user's name, the update profile link and the sign out link are added, as these are standard behaviour in any CMS, however, if required, you can overwrite these links like so: -------------------------------------------------------------------------------- {% block user_nav -%} {% macro user_nav_list() %} ... {% endmacro %} {{ _nav.user_nav(user_nav_list()) }} {%- endblock %} -------------------------------------------------------------------------------- #} {# Prime nav -- The containing element for the `prime_nav` component. Must be passed `list` as a mixin which should contain the list of links in for the navigation. #} {% macro prime_nav(list) -%}
{{ list }}
{%- endmacro %} {# Nav list -- A mixin used in conjunction with the python generated navigation items to work out whether the item passed is a parent or child element in the navigation tree structure. #} {% macro nav_list(item) -%} {% if item.parent -%} {{ nav_item(item) }} {%- else -%} {% for child in item.children -%} {{ nav_item(child) }} {%- endfor %} {%- endif %} {%- endmacro %} {# Nav item -- A mixin used in conjunction with the python generated navigation items to build the container for a navigation item and it's sub-list if it is a parent item. #} {% macro nav_item(item) -%} {% if item.data.group %}
{% if item.label %} {{ item.label }} {% endif %}
{% for child in item.children -%} {{ nav_list(child) }} {%- endfor %}
{% else %}
{{ nav_link(item) }} {% if item.is_parent -%}
{% for child in item.children -%} {{ nav_list(child) }} {%- endfor %}
{%- endif %}
{% endif %} {%- endmacro %} {# Nav link -- A mixin used in conjunction with the python generated navigation items to build the link element. #} {% macro nav_link(item) -%} {% if item.endpoint -%} {% set badge = item.badge %} {% set icon = item.data.icon %} {% set link = item.query %} {% if link.allowed -%} {{ nav_link_label(item.label, badge, icon) }} {%- else -%} {{ nav_link_label(item.label, badge, icon) }} {%- endif %} {%- elif item.fixed_url -%} {{ nav_link_label(item.label, badge, icon) }} {%- else -%} {{ nav_link_label(item.label, badge, icon) }} {%- endif %} {%- endmacro %} {# Nav link text -- A mixin used in conjunction with the python generated navigation items to build the text and badge (if applicable) for the nav link. #} {% macro nav_link_label(text, badge, icon) -%} {{ text }} {% if badge in [True, False] -%} {%- elif badge -%} {{ badge if badge < 100 else '...' }} {%- endif %} {%- endmacro %} {# User nav -- The containing element for the `user_nav` component. Must be passed `list` as a mixin which should contain the list of links used for the navigation. It assumes that a badge is passed to the but will default to display the user's name if a badge is not available. At least one of these 2 must be passed. If neither are available/needed, you can overide the entire `user_nav` component tp remove it from the page. #} {% macro user_nav(list, user=None, badge=None, mobile_badge=None) -%}
{% if badge %} {{ badge }} {% elif user %} {{ user.first_name }}
{{ user.last_name }} {% endif %}
{% if mobile_badge %} {{ mobile_badge }} {% elif user %} {{ user.full_name }} {% endif %}
{{ list }}
{%- endmacro %}