templates/menu/main-template.html.twig line 1

  1. {% extends "@KnpMenu/menu.html.twig" %}
  2. {% import 'knp_menu.html.twig' as knp_menu %}
  3. {% block list %}
  4.     {# {{ dump(item,matcher) }} #}
  5.     {% if item.hasChildren and options.depth is not same as(0) and item.displayChildren %}
  6.         {# {% import _self as knp_menu %} #}
  7.         <nav class="section-navigation">
  8.             <div class="section-navigation__inner container">
  9.                 {{ block('children_desktop') }}
  10.                 {{ block('children_mobile') }}
  11.             </div>
  12.         </nav>
  13.         {% set selectedMenu = null %}
  14.         {% for it in item.children %}
  15.             {%- if matcher.isCurrent(it) or matcher.isAncestor(it, options.matchingDepth) %}
  16.                 {% if it.children|length %}
  17.                     {% set selectedMenu=it %}
  18.                 {% endif %}
  19.             {% endif %}
  20.         {% endfor %}
  21.         {% if selectedMenu %}
  22.             {{ block('second_level') }}
  23.         {% endif %}
  24.     {% endif %}
  25. {% endblock %}
  26. {% block second_level %}
  27.     <nav class="secondary-section-navigation">
  28.         <ul class="secondary-section-navigation__nav container">
  29.             {% for item in selectedMenu %}
  30.                 <li class="secondary-section-navigation__nav-link
  31.                 {% if matcher.isCurrent(item) or matcher.isAncestor(item, options.matchingDepth) %}
  32.                     secondary-section-navigation__nav-link_active
  33.                 {% endif %}
  34. ">
  35.                     {{ block("linkElement") }}
  36.                 </li>
  37.             {% endfor %}
  38.         </ul>
  39.     </nav>
  40. {% endblock %}
  41. {% block children_desktop %}
  42.     {# save current variables #}
  43.     {% set currentOptions = options %}
  44.     {% set currentItem = item %}
  45.     {# update the depth for children #}
  46.     {% if options.depth is not none %}
  47.         {% set options = options|merge({'depth': currentOptions.depth - 1}) %}
  48.     {% endif %}
  49.     {# update the matchingDepth for children #}
  50.     {% if options.matchingDepth is not none and options.matchingDepth > 0 %}
  51.         {% set options = options|merge({'matchingDepth': currentOptions.matchingDepth - 1}) %}
  52.     {% endif %}
  53.     {% set selectedMenu=null %}
  54.     <ul class="section-navigation__nav">
  55.         {% for item in currentItem.children %}
  56.             {%- if matcher.isCurrent(item) or matcher.isAncestor(item, options.matchingDepth) %}
  57.                 {% set selectedMenu=item %}
  58.             {% endif %}
  59.             {{ block('item_desktop') }}
  60.         {% endfor %}
  61.     </ul>
  62.     {# {% if selectedMenu and selectedMenu.children|length %}
  63.         <ul class="section-navigation__nav section-navigation__submenu ">
  64.     #}{# {{ dump(selectedMenu) }} #}{#
  65. {% for item in selectedMenu.children %}
  66.     {{ block('item_desktop') }}
  67. {% endfor %}
  68. </ul>
  69. {% endif %}
  70. #}
  71.     {# restore current variables #}
  72.     {% set item = currentItem %}
  73.     {% set options = currentOptions %}
  74. {% endblock %}
  75. {% block children_mobile %}
  76.     {# save current variables #}
  77.     {% set currentOptions = options %}
  78.     {% set currentItem = item %}
  79.     {# update the depth for children #}
  80.     {% if options.depth is not none %}
  81.         {% set options = options|merge({'depth': currentOptions.depth - 1}) %}
  82.     {% endif %}
  83.     {# update the matchingDepth for children #}
  84.     {% if options.matchingDepth is not none and options.matchingDepth > 0 %}
  85.         {% set options = options|merge({'matchingDepth': currentOptions.matchingDepth - 1}) %}
  86.     {% endif %}
  87.     {# <div class="section-navigation__mobile-nav">
  88.         <div class="section-navigation__mobile-nav-title">Об учебном заведении</div>
  89.         <a class="section-navigation__mobile-nav-button" data-toggle="collapse"
  90.            data-target=".section-navigation__mobile-nav-menu">
  91.             <i class="far fa-bars"></i></a>
  92.     </div>
  93.     <div class="section-navigation__mobile-nav-menu collapse">
  94.         <ul>
  95.             <li class="section-navigation__mobile-nav-link"><a href="/">Олимпиады</a></li>
  96.             <li class="section-navigation__mobile-nav-link"><a href="/">Новости</a></li>
  97.             <li class="section-navigation__mobile-nav-link"><a href="/">События</a></li>
  98.             <li class="section-navigation__mobile-nav-link"><a href="/">Контакты</a></li>
  99.         </ul>
  100.     </div> #}
  101.     {% for item in currentItem.children|filter(item => matcher.isCurrent(item) or matcher.isAncestor(item, options.matchingDepth) ) %}
  102.         {{ block('item_mobile_current') }}
  103.     {% endfor %}
  104.     {% set otherElements =currentItem.children|filter(item => false == matcher.isCurrent(item) and false ==  matcher.isAncestor(item, options.matchingDepth)) %}
  105.     {% if otherElements|length %}
  106.         <div class="section-navigation__mobile-nav-menu collapse">
  107.             <ul>
  108.                 {% for item in  otherElements %}
  109.                     {{ block('item_mobile_other') }}
  110.                 {% endfor %}
  111.             </ul>
  112.         </div>
  113.     {% endif %}
  114.     {# restore current variables #}
  115.     {% set item = currentItem %}
  116.     {% set options = currentOptions %}
  117. {% endblock %}
  118. {% block item_mobile_current %}
  119.     <div class="section-navigation__mobile-nav">
  120.         <div class="section-navigation__mobile-nav-title">{{ block('simpleLinkElement') }}</div>
  121.         <a class="section-navigation__mobile-nav-button" data-toggle="collapse"
  122.            data-target=".section-navigation__mobile-nav-menu">
  123.             <i class="far fa-bars"></i></a>
  124.     </div>
  125. {% endblock %}
  126. {% block item_mobile_other %}
  127.     {%- set classes = item.attribute('class') is not empty ? [item.attribute('class')] : [] %}
  128.     {%- set classes = classes|merge(["section-navigation__mobile-nav-link",options.itemMobileClass|default]) %}
  129.     {%- set attributes = item.attributes %}
  130.     {%- if classes is not empty %}
  131.         {%- set attributes = attributes|merge({'class': classes|join(' ')}) %}
  132.     {%- endif %}
  133.     <li{{ knp_menu.attributes(attributes) }}>
  134.         {# {%- if item.uri is not empty and (not matcher.isCurrent(item) or options.currentAsLink) %}
  135.                 {{ block('linkElement') }}
  136.             {%- else %} #}
  137.         {{ block('linkElement') }}
  138.         {# {%- endif %} #}
  139.     </li>
  140.     {# <li class="section-navigation__mobile-nav-link"><a href="/">Контакты</a></li> #}
  141. {% endblock %}
  142. {% block item_desktop %}
  143.     {# {{ dump(knp_menu) }} #}
  144.     {% if item.displayed %}
  145.         {# building the class of the item #}
  146.         {%- set classes = item.attribute('class') is not empty ? [item.attribute('class')] : [] %}
  147.         {%- set classes = classes|merge(["section-navigation__nav-link",options.itemDesktopClass|default]) %}
  148.         {%- if matcher.isCurrent(item) %}
  149.             {%- set classes = classes|merge([options.currentClass]) %}
  150.         {%- elseif matcher.isAncestor(item, options.matchingDepth) %}
  151.             {%- set classes = classes|merge([options.ancestorClass]) %}
  152.         {%- endif %}
  153.         {%- if item.actsLikeFirst %}
  154.             {%- set classes = classes|merge([options.firstClass]) %}
  155.         {%- endif %}
  156.         {%- if item.actsLikeLast %}
  157.             {%- set classes = classes|merge([options.lastClass]) %}
  158.         {%- endif %}
  159.         {% if item.hasChildren %}
  160.             {%- set classes = classes|merge(["submenu"]) %}
  161.         {% endif %}
  162.         {# Mark item as "leaf" (no children) or as "branch" (has children that are displayed) #}
  163.         {% if item.hasChildren and options.depth is not same as(0) %}
  164.             {% if options.branch_class is not empty and item.displayChildren %}
  165.                 {%- set classes = classes|merge([options.branch_class]) %}
  166.             {% endif %}
  167.         {% elseif options.leaf_class is not empty %}
  168.             {%- set classes = classes|merge([options.leaf_class]) %}
  169.         {%- endif %}
  170.         {%- set attributes = item.attributes %}
  171.         {%- if classes is not empty %}
  172.             {%- set attributes = attributes|merge({'class': classes|join(' ')}) %}
  173.         {%- endif %}
  174.         {# displaying the item #}
  175.         {# {% import _self as knp_menu %} #}
  176.         <li{{ knp_menu.attributes(attributes) }}>
  177.             {# {%- if item.uri is not empty and (not matcher.isCurrent(item) or options.currentAsLink) %}
  178.                 {{ block('linkElement') }}
  179.             {%- else %} #}
  180.             {{ block('linkElement') }}
  181.             {# {%- endif %} #}
  182.         </li>
  183.     {% endif %}
  184. {% endblock %}
  185. {% block label %}{% if options.allow_safe_labels and item.getExtra('safe_label', false) %}{{ item.label|raw }}{% else %}{{ item.label|trans }}{% endif %}{% endblock %}
  186. {% block linkElement -%}
  187.     {%- set classes = item.linkAttributes('class') is not empty ? [item.linkAttributes('class')] : [] %}
  188.     {%- if matcher.isCurrent(item) %}
  189.         {%- set classes = classes|merge([options.currentClass]) %}
  190.     {%- elseif matcher.isAncestor(item, options.matchingDepth) %}
  191.         {%- set classes = classes|merge([options.ancestorClass]) %}
  192.     {%- endif %}
  193.     {%- set attributes = item.linkAttributes %}
  194.     {%- if classes is not empty %}
  195.         {%- set attributes = attributes|merge({'class': classes|join(' ')}) %}
  196.     {%- endif %}
  197.     <a href="{{ item.uri|default("#") }}"{{ knp_menu.attributes(attributes) }}>{{ block('label') }}</a>
  198. {%- endblock %}
  199. {% block simpleLinkElement -%}
  200.     <a href="{{ item.uri|default("#") }}">{{ block('label') }}</a>
  201. {%- endblock %}