Collection List [Refresh theme]: A-Z function and reduce card size

Hello, I am hoping someone can help. I have been working on updating our website to the new Shopify OS theme Refresh and have encountered an issue with the collections list. We have some custom code on our current website that achieved the A-Z structure with large letters etc.

https://hoopersstores.com/collections

{% comment %} The code below calls in the brands starting with letters from A-Z, then the numbers from 0-9 {% endcomment %}

{% assign current = "" %}

{% for collection in collections %}
{% unless collection.title == 'Accessories' or collection.title == 'Beauty' {% assign first_letter = collection.title | strip_html | upcase | truncate: 1, '' %}
{% if "0123456789" contains first_letter %} {% continue %} {% endif %}
{% unless first_letter == current %}

- {{ first_letter }}

{% endunless %}
- {{ collection.title }}

{% assign current = first_letter %}

{% endunless %}
{% endfor %}

{% for collection in collections %}
{% assign first_letter = collection.title | strip_html | upcase | truncate: 1, '' %}
{% unless "0123456789" contains first_letter %} {% break %}{% endunless %}
{% unless first_letter == current %}

- {{ first_letter }}

{% endunless %}
- {{ collection.title }}
{% assign current = first_letter %}

{% endfor %}

Here is where I have got to with the refresh theme… but I can’t get the A-Z function working or indeed even reduce the size of the collection cards. Please can someone help?

Hi @Alex1993 ,

May I suggest code below:

{%- liquid
   assign collectionss =  collections | sort_natural
   assign letters = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,0;1;2;3;4;5;6;7;8;9'
   assign letters_arr = letters | split: ','
  -%}

    
      {%- for letter in letters_arr -%}
        {% assign has_sub  = false  %}
        {% capture show_html %}
          - <strong>
              {%  if letter == '0;1;2;3;4;5;6;7;8;9' %}
                0-9
              {%  else %}
                {{ letter }}
              {%  endif %}
            </strong>
            

              {%- for collection in collectionss -%}
                {% assign first_letter = collection.title | slice: 0 | downcase  %}
                {% if letter  contains first_letter %}
                  {% assign has_sub  = true  %}
                - {{ collection.title }}
              
                {% endif %}
              {%- endfor -%}
            
          
          {%  endcapture %}
          {%  if has_sub  %}
            {{ show_html }}
          {%  endif %}
       {%- endfor -%}
    

    
  

Thank you for this code, I’ve put it in and it has worked. Is there an easy adjustment to have the brands listed in multiple columns underneath their respective letter?

Hi,

Could you share your URL store? We need add some CSS code to do it. I need check your store to suggest a solution.

Of course, the URL is https://hoopers-stores.myshopify.com. Our live website is https://hoopersstores.com.

Hi,

You can try this code below:

{%- liquid
   assign collectionss =  collections | sort_natural
   assign letters = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,0;1;2;3;4;5;6;7;8;9'
   assign letters_arr = letters | split: ','
  -%}

    
      {%- for letter in letters_arr -%}
        {% assign has_sub  = false  %}
        {% capture show_html %}
          - <strong>
              {%  if letter == '0;1;2;3;4;5;6;7;8;9' %}
                0-9
              {%  else %}
                {{ letter }}
              {%  endif %}
            </strong>
            

              {%- for collection in collectionss -%}
                {% assign first_letter = collection.title | slice: 0 | downcase  %}
                {% if letter  contains first_letter %}
                  {% assign has_sub  = true  %}
                - {{ collection.title }}
              
                {% endif %}
              {%- endfor -%}
            
          
          {%  endcapture %}
          {%  if has_sub  %}
            {{ show_html }}
          {%  endif %}
       {%- endfor -%}
    

    
  

Thank you this code worked well. Just needs some more CSS work and then it can be used.