templates/_menu/city_stations_links.html.twig line 1

Open in your IDE?
  1. {#
  2. /* -------------------------------------------------------------------------- */
  3. /*                   Обычный лайтбокс выбора метро в паблике                  */
  4. /* -------------------------------------------------------------------------- */
  5. #}
  6. {% apply spaceless %}
  7. {# <ul class="select-metro buttons">
  8.     {% for stationItem in item.children|slice(1) %}
  9.         {% set labelParts = stationItem.label|split('(', 2) %}
  10.         {% set labelCounts = labelParts[1] %}
  11.         {# <li><button type="button" onclick="location='{{ stationItem.uri }}'" class="nonstd-hover-link">{{ labelParts[0]|trim }}</button><span>{{ labelCounts|slice(0, labelCounts|length - 1) }}</span></li> #!}
  12.         <li><a href="{{ stationItem.uri }}" class="nonstd-hover-link">{{ labelParts[0]|trim }}</a><span>{{ labelCounts|slice(0, labelCounts|length - 1) }}</span></li>
  13.     {% else %}
  14.         {% set defaultCity = default_city() %}
  15.         {% for station in defaultCity.stations %}
  16.             {% set labelParts = station.name|split('(', 2) %}
  17.             {% set labelCounts = labelParts[1] %}
  18.             {# <li><button type="button" onclick="location='{{ path('profile_list.list_by_station', {'city': defaultCity.uriIdentity, 'station': station.uriIdentity}) }}'" class="nonstd-hover-link">{{ labelParts[0]|trim }}</button><span>{{ labelCounts|slice(0, labelCounts|length - 1) }}</span></li> #!}
  19.             <li><a href="{{ path('profile_list.list_by_station', {'city': defaultCity.uriIdentity, 'station': station.uriIdentity}) }}" class="nonstd-hover-link">{{ labelParts[0]|trim }}</a><span>{{ labelCounts|slice(0, labelCounts|length - 1) }}</span></li>
  20.         {% endfor %}
  21.     {% endfor %}
  22. </ul> #}
  23. <div class="catalog-metro-container-block">
  24.     <div class="catalog-metro-container" dialog-content>
  25.         {% set firstLetter = null %}
  26.         {% set sorted_stations = item.children|slice(1)|sort((a, b) => a.name|upper <=> b.name|upper) %}
  27.         {% for station in sorted_stations %}
  28.         {# {% if loop.index < 5 %}
  29.         {{dump(station.extras)}}
  30.         {% endif %} #}
  31.         {# В stationItem.label Приходит строка формата "Станция Новоизмайловская (24)" - название станции и кол-во элементов найденных по этой станции в скобочках
  32.         Напиши оптимальный метод получения количества и названия станции для использования в twig #}
  33.         {# {% set [name, count] = station.label|split('(', 2) %} #}
  34.             {% set data = station.label|split('(', 2) %}
  35.             {% set name = data[0]|trim %}
  36.             {% set count = data[1]|slice(0, -1)|trim %}
  37.             {% set firstChar = station.label|slice(0, 1)|upper %}
  38.             {% if firstLetter != firstChar %}
  39.                 {% if loop.index != 1 %}</div>{% endif %}
  40.                 {% set firstLetter = firstChar %}
  41.                 <div class="catalog catalog-metro mb-4">
  42.                     <div class="first-letter mb-2 fw-700 d-flex-c">
  43.                         {{- firstLetter -}}
  44.                     </div>
  45.             {% endif %}
  46.             <div class="catalog-item">
  47.                 <a class="metro-link d-flex-c" href="{{ station.uri }}">
  48.                     {% include 'components/metro/icon_generate.partial.twig' with {data: station.extras.lines} %}
  49.                     <span class="metro-name mr-1">{{ name }}</span>
  50.                     <span class="metro-count d-flex-c clr-main-text fw-600">{{ count }}</span>
  51.                 </a>
  52.             </div>
  53.         {% endfor %}
  54.     </div>
  55. </div>
  56. {% endapply %}