In Liquid, a common way to loop through a list is to use the for tag. Here is an example:

{% for item in list %}
    {{ item }}
{% endfor %}

In this example, the for tag is used to iterate over the elements in the list object. For each element in the list, the item variable is set to the current element, and the code inside the for block is executed. This code simply outputs the value of item, but you can perform any logic you want inside the for block.

If you are dealing with a linked list, you can loop through it in a similar way, but you will need to use a different approach to access the elements in the list. In a linked list, each element (or “node”) contains a reference to the next node in the list. To loop through a linked list, you will need to start at the first node and follow the links between the nodes until you reach the end of the list.

Here is an example of how you might do this in Liquid:

{% assign current_node = list.first %}

{% while current_node %}
    {{ current_node.value }}
    {% assign current_node = %}
{% endwhile %}

In this example, we use a while loop to iterate over the elements in the linked list. The while loop continues to run as long as the current_node variable is not null, which indicates that we have reached the end of the list. Inside the while block, we output the value of the current node, and then update the current_node variable to point to the next node in the list by accessing the next property of the current node.

It is important to note that this example assumes that the linked list is implemented in a specific way, with each node having a value and next property. The exact implementation of the linked list will depend on your specific use case, so you may need to adjust this code accordingly.

Example of looping through and displaying a link list

{% for link in linklists.*linklisthere*.links %}
    <li class=””>
        <a href=”{{ link.url }}”>{{ link.title }}</a>
{% endfor %}

Replace *linklisthere* with the name of your navigation linklist.


For more shopify ecommerce help and custom theme development contact us here.