templates/_menu/breadcrumbs.html.twig line 1

Open in your IDE?
  1. {% if item.children|length > 1 %}
  2.     {# Перегоняем в индексированный массив #}
  3.     {% set children = [] %}
  4.     {% for breadcrumb_item in item.children %}
  5.         {% set children = children|merge([breadcrumb_item]) %}
  6.     {% endfor %}
  7.     {% set route = app.request.get('_route') %}
  8.     {% set city = app.request.get('city') ?? null %}
  9.     {% set locale = app.request.locale ?? 'ru' %}
  10.     {% if route == 'profile_preview.page' %}
  11.         {#
  12.                 На странице анкеты Москвы выводим крошки вида
  13.                 Главная / ЗАО (то есть ссылка на округ) / Дорогомилово (то есть ссылка на район) / Кутузовская (то есть ссылка на метро) / индивидуалка Аня (Аня простым текстом, без ссылки)
  14.                 (согласно https://redminez.net/issues/27876),
  15.                 а на остальных Главная / Город / индивидуалка Имя
  16.         #}
  17.         {% set profile = options.profile ?? null %}
  18.         {% set main = [{label: 'Главная', uri: path('homepage')}, {label: city.name, uri: path('profile_list.list_by_city', {city: city.uriIdentity})}] %}
  19.         {% set children = main|merge([children[1]]) %}
  20.         <ul class="breadcrumbs" vocab="http://schema.org/" typeof="BreadcrumbList">
  21.             <li class="" property="itemListElement" typeof="ListItem">
  22.                 <a href="{{ (children|first).uri }}" property="item" typeof="WebPage"><span property="name">{{ (children|first).label }}</span></a>
  23.                 <meta property="position" content="0">
  24.             </li>
  25.             {% set position = 1 %}
  26.             {% if city and city.id == 1 %}
  27.                 {% set station = profile.stations|length ? profile.stations[0] : null %}
  28.                 {% if profile and station and station.district and station.county %}
  29. {#
  30.                     <li class="" property="itemListElement" typeof="ListItem">
  31.                         <a href="{{ path('profile_list.list_by_county', {city: city.uriIdentity, county: station.county.uriIdentity }) }}" property="item" typeof="WebPage"><span property="name">{{ station.county.name|trans }}</span></a>
  32.                         <meta property="position" content="1">
  33.                     </li>
  34.                     <li class="" property="itemListElement" typeof="ListItem">
  35.                         <a href="{{ path('profile_list.list_by_district', {city: city.uriIdentity, district: station.district.uriIdentity}) }}" property="item" typeof="WebPage"><span property="name">{{ station.district.name|trans }}</span></a>
  36.                         <meta property="position" content="2">
  37.                     </li>
  38. #}
  39.                     <li class="" property="itemListElement" typeof="ListItem">
  40.                         <a href="{{ path('station_list.page', {city: city.uriIdentity}) }}" property="item" typeof="WebPage"><span property="name">Метро</span></a>
  41.                         <meta property="position" content="2">
  42.                     </li>
  43.                     <li class="" property="itemListElement" typeof="ListItem">
  44.                         <a href="{{ path('profile_list.list_by_station', {city: city.uriIdentity, station: station.uriIdentity}) }}" property="item" typeof="WebPage"><span property="name">{{ station.name|trans }}</span></a>
  45.                         <meta property="position" content="3">
  46.                     </li>
  47.                     {% set position = 4 %}
  48.                 {% else %}
  49.                     {#
  50.                         если у анкеты нет станции, то:
  51.                         Южный (ЮАО), Донской, Ленинский проспект
  52.                     #}
  53. {#
  54.                     <li class="" property="itemListElement" typeof="ListItem">
  55.                         <a href="{{ path('profile_list.list_by_county', {city: city.uriIdentity, county: 'yuzhnyj-yuao' }) }}" property="item" typeof="WebPage"><span property="name">{{ locale == 'ru' ? 'Южный (ЮАО)' : 'South (SAD)' }}</span></a>
  56.                         <meta property="position" content="1">
  57.                     </li>
  58.                     <li class="" property="itemListElement" typeof="ListItem">
  59.                         <a href="{{ path('profile_list.list_by_district', {city: city.uriIdentity, district: 'donskoj'}) }}" property="item" typeof="WebPage"><span property="name">{{ locale == 'ru' ? 'Донской' : 'Donskoy' }}</span></a>
  60.                         <meta property="position" content="2">
  61.                     </li>
  62.                     #}
  63.                     <li class="" property="itemListElement" typeof="ListItem">
  64.                         <a href="{{ path('station_list.page', {city: city.uriIdentity}) }}" property="item" typeof="WebPage"><span property="name">Метро</span></a>
  65.                         <meta property="position" content="2">
  66.                     </li>
  67.                     <li class="" property="itemListElement" typeof="ListItem">
  68.                         <a href="{{ path('profile_list.list_by_station', {city: city.uriIdentity, station: 'leninskij-prospekt'}) }}" property="item" typeof="WebPage"><span property="name">{{ locale == 'ru' ? 'Ленинский проспект' : 'Leninskij prospekt' }}</span></a>
  69.                         <meta property="position" content="3">
  70.                     </li>
  71.                     {% set position = 4 %}
  72.                 {% endif %}
  73.             {% else %}
  74.                 <li class="" property="itemListElement" typeof="ListItem">
  75.                     <a href="{{ path('profile_list.list_by_city', {city: city.uriIdentity}) }}" property="item" typeof="WebPage"><span property="name">{{ city.name }}</span></a>
  76.                     <meta property="position" content="1">
  77.                 </li>
  78.                 {% set position = 2 %}
  79.             {% endif %}
  80.             <li property="itemListElement" typeof="ListItem">
  81.                 <span property="name">{{ profile.name|trans }}, {{ profile.personParameters.age }}</span>
  82.                 <meta property="position" content="{{ position }}">
  83.             </li>
  84.         </ul>
  85.     {% else %}
  86.         <ul class="breadcrumbs" vocab="http://schema.org/" typeof="BreadcrumbList">
  87.             {% if route == 'profile_list.list_by_district' %}
  88.                 {# Убираем название округа #}
  89.                 {% set children = children | map((k) => k) | filter((v, k) => k != 2) %}
  90.             {% elseif route == 'profile_list.list_by_county' %}
  91.                 {# Убираем слово районы #}
  92.                 {% set children = [children[0], children[2]] %}
  93.             {% elseif route == 'profile_list.list_by_station' %}
  94.                 {# Убираем слово районы #}
  95.                 {% set children = [
  96.                     children[0],
  97.                     { label: 'Метро', uri: path('station_list.page', {city: city.uriIdentity}) },
  98.                     { label: children[1].label, uri: children[1].uri }
  99.                 ] %}
  100.             {% endif %}
  101.             {% if city.id == 1 %}
  102.                 {# Делаем првый элемент "Главная" #}
  103.                 {% set main = [{label: 'Главная', uri: path('homepage')}] %}
  104.                 {% set children = main|merge(children|slice(1, children|length - 1)) %}
  105.             {% else %}
  106.                 {# Делаем првый элемент "Главная", второй - город #}
  107.                 {% set main = [{label: 'Главная', uri: path('homepage')}, {label: city.name, uri: path('profile_list.list_by_city', {city: city.uriIdentity})}] %}
  108.                 {% set children = main|merge(children|slice(1, children|length - 1)) %}
  109.             {% endif %}
  110.             {% for breadcrumb_item in children %}
  111.                 <li class="{% if loop.last %}last-crumb{% endif %}" property="itemListElement" typeof="ListItem">
  112.                     {% if not loop.last %}
  113.                         <a href="{{ breadcrumb_item.uri }}" property="item" typeof="WebPage"><span property="name">{{ breadcrumb_item.label|trans({}, 'breadcrumbs') }}</span></a>
  114.                     {% else %}
  115.                         <span property="name">{{ breadcrumb_item.label|trans({}, 'breadcrumbs') }}</span>
  116.                     {% endif %}
  117.                     <meta property="position" content="{{ loop.index }}">
  118.                 </li>
  119.             {% endfor %}
  120.         </ul>
  121.     {% endif %}
  122. {% endif %}