Liquid loop logic help for vendors list page

Solved
Highlighted
Tourist
6 1 0

Hi! I am building a brands list page from scratch using some dummy data for my vendor_list array while testing my code and am having trouble getting vendors that begin with numbers to appear under "Letter: #". The following code works for vendors that begin with letters. Any ideas on how to accomplish this? I appreciate it!

<div class="container-indent">
  <div class="container">
    {{ page.content }}
    
    {% assign alphabet_list = "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,#" | split: ',' %}
    {% assign vendor_list = "Facebook,Apple,Google,Amazon,45North" | split: ',' | sort %}

	{% for letter in alphabet_list %}
        <a href="#">Letter: {{ letter }}</a><br>
 		{% for v in vendor_list %}
			{% assign first_letter = v | truncate: 1, "" %}
    
      			{% if letter == first_letter %}
    			  {{v}}
			{% endif %}
   
		{% endfor %}
    		<br>
	{% endfor %}

  </div>
</div>
0 Likes
Highlighted

What's exactly do you want to filter to the vendor start with a number?

CRO Expert at PageFly - Advanced Shopify Page Builder.
- PageFly Page Builder: Website | Facebook | LinkedIn | Group
- [Tutorial] How to customize Shopify product page: academy.pagefly.io/customize-shopify-product-pages.
0 Likes
Highlighted
Tourist
6 1 0

Not sure I understand your question. I'm trying to create a list that looks like this:

 

Letter: A

Amazon Apple Adidas

 

Letter: B

Boeing Bentley

(...and so on)

Letter: #

45North 3M 7UP

 

Where any brand that begins with 0-9 is placed under "Letter: #"

0 Likes
Highlighted
Tourist
6 1 0

This is an accepted solution.

I solved it by repeating the for loop logic for a number list. Seems a bit cluttered but it works. Is there a better way?

<div class="container-indent">
  <div class="container">
    {{ page.content }}
    
    {% assign alphabet_list = "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" | split: ',' %}
    {% assign number_list = "0,1,2,3,4,5,6,7,8,9" | split: ',' %}
	{% assign vendor_list = "Facebook,Apple,Google,Amazon,45North,30South" | split: ',' | sort %}

	{% for letter in alphabet_list %}
           <a href="#">Letter: {{ letter }}</a><br>
 	       {% for v in vendor_list %}
		  {% assign first_letter = v | truncate: 1, "" %}
    		
      		  {% if first_letter == letter %}
    		    {{v}}
		  {% endif %}
	       {% endfor %}
             <br>
	{% endfor %}
    
    <a href="#">Letter: #</a><br>
    
    {% for number in number_list %}
 	 {% for v in vendor_list %}
            {% assign first_letter = v | truncate: 1, "" %}
    		
             {% if first_letter == number %}
    	        {{v}}
	     {% endif %}

	     {% endfor %}
	{% endfor %}
 
  </div>
</div>  

 

0 Likes