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" dialog-content>
  24.     {% set firstLetter = null %}
  25.     {% set sorted_stations = item.children|slice(1)|sort((a, b) => a.name|upper <=> b.name|upper) %}
  26.     {% for station in sorted_stations %}
  27.     {# {% if loop.index < 5 %}
  28.     {{dump(station.extras)}}
  29.     {% endif %} #}
  30.     {# В stationItem.label Приходит строка формата "Станция Новоизмайловская (24)" - название станции и кол-во элементов найденных по этой станции в скобочках
  31.     Напиши оптимальный метод получения количества и названия станции для использования в twig #}
  32.     {# {% set [name, count] = station.label|split('(', 2) %} #}
  33.         {% set data = station.label|split('(', 2) %}
  34.         {% set name = data[0]|trim %}
  35.         {% set count = data[1]|slice(0, -1)|trim %}
  36.         {% set firstChar = station.label|slice(0, 1)|upper %}
  37.         {% if firstLetter != firstChar %}
  38.             {% if loop.index != 1 %}</div>{% endif %}
  39.             {% set firstLetter = firstChar %}
  40.             <div class="catalog catalog-metro mb-4">
  41.                 <div class="first-letter mb-2 fw-700 d-flex-c">
  42.                     {{- firstLetter -}}
  43.                 </div>
  44.         {% endif %}
  45.         <div class="catalog-item">
  46.             <a class="metro-link d-flex-c" href="{{ station.uri }}">
  47.                 {% include 'components/metro/icon_generate.partial.twig' with {data: station.extras.lines} %}
  48.                 <span class="metro-name mr-1">{{ name }}</span>
  49.                 <span class="metro-count d-flex-c clr-main-text fw-600">{{ count }}</span>
  50.             </a>
  51.         </div>
  52.     {% endfor %}
  53. </div>
  54. {% endapply %}