bogatyrevata / klasstrueda

0 stars 0 forks source link

Исправить шапку сайта в разделе курсы и в админке,ч тобы правильно отображалась #95

Closed bogatyrevata closed 1 week ago

bogatyrevata commented 1 week ago

Переписан макрос, добавлен флаг is_admin в меню в админке, чтобы макрос определял где какое меню.

bogatyrevata commented 1 week ago

  {% if is_admin %}
    {% set breadcrumbs = g.breadcrumbs %}
    {% set title = breadcrumbs | map(attribute='title') | first %}
  {% else %}
    {% set menu = g.menu %}
    {% set active_item = request.path.strip('/') %}
    {% set title = menu | selectattr('href', '==', active_item) | map(attribute='title') | first %}
  {% endif %}

  <div class="container-fluid page-header py-6 my-4 mt-0 wow fadeIn" data-wow-delay="0.1s">
    <div class="container text-center">
      {% for item in g.menu %}
        {% if item.submenu %}
          {% for sub_item in item.submenu %}
            {% if sub_item.href == active_item %}
              <h1 class="display-4 text-white animated slideInDown mb-4">{{ sub_item.title }}</h1>
            {% endif %}
          {% endfor %}
        {% endif %}
      {% endfor %}
      {% if title %}
        <h1 class="display-4 text-white animated slideInDown mb-4">{{ title }}</h1>
      {% endif %}
      <nav aria-label="breadcrumb animated slideInDown">
        <ol class="breadcrumb justify-content-center mb-0">
          <li class="breadcrumb-item">
            <a class="text-white" href="{{ url_for('core.index') }}">Главная</a>
          </li>

          {% if is_admin %}
            {% for breadcrumb in breadcrumbs %}
              <li class="breadcrumb-item {{ 'text-primary active' if loop.last else '' }}"
                  aria-current="{{ 'page' if loop.last else '' }}">
                {% if breadcrumb.controller and not loop.last %}
                  <a class="text-white" href="{{ url_for(breadcrumb.controller) }}">{{ breadcrumb.title }}</a>
                {% else %}
                  {{ breadcrumb.title }}
                {% endif %}
              </li>
            {% endfor %}
          {% else %}
            {% for item in menu %}
              {% if item.submenu %}
                {% for sub_item in item.submenu %}
                  {% if sub_item.href == active_item %}
                    <li class="breadcrumb-item text-primary active" aria-current="page">{{ sub_item.title }}</li>
                  {% endif %}
                {% endfor %}
              {% endif %}
            {% endfor %}
            {% if title %}
              <li class="breadcrumb-item text-primary active" aria-current="page">{{ title }}</li>
            {% endif %}
          {% endif %}
        </ol>
      </nav>
    </div>
  </div>
{% endmacro %}```