How to output a list in Shopify Liquid where each list item is grouped by first letter?

Anish-SDG
Tourist
5 0 0

I have the following list stored in an array:

array.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

The goal is to have the output look like this:

correct output.png

 

Here is what I have so far:

code.png

 

bad output.png

 

Any ideas?

Replies 2 (2)

LitExtension
Shopify Partner
4860 1002 1145

Hi @Anish-SDG,

Please change code:

{% assign check = '' %}
  {% for link in linklist %}
    {%- assign first_letter = link.title | slice: 0 | capitalize -%}
  	{% if first_letter != check %}
  	  <span>{{ first_letter }}</span>
  	  {% assign check = first_letter %}
    {% endif %}
    <ul>
      <li>
        <a href="#">{{ link.title }}</a>
      </li>
    </ul>
  {% endfor %}

Hope it helps!

LitExtension - Shopping Cart Migration Expert
Check out our Shopify migration app to migrate your online store to Shopify
LitExtension
Shopify Partner
4860 1002 1145

Hi @Anish-SDG,

I saw you liked my answer. If it helped you solve your issue, please mark it as a solution. Thank you and good luck.

LitExtension - Shopping Cart Migration Expert
Check out our Shopify migration app to migrate your online store to Shopify