Create an array in Shopify's liquid

According to Shopify’s documentation, you can’t create arrays with liquid.

Unfortunately, that means you can’t do something simple and clean like this:

{% assign fruits = ["orange", "apple", "peach"] %}

Thankfully, there’s a workaround!

You can use the split filter to create accessible arrays in liquid:

{% assign fruits = "orange,apple,peach" | split: ',' %}

It’s not particularly elegant, but it does the job. You can then loop over this array and do whatever you like:

{% for fruit in fruits %}
  {{ fruit }}
{% endfor %}

And voila.

Being able to capture arrays with liquid opens up a lot of possible applications for your Shopify store!

Find this helpful? You might also like our apps:

  • Customer Fields allows you to build custom registration forms and retrieve valuable data from customers at just the right time.
  • Meteor Mega Menu offers a variety of beautiful dropdown menu templates which you can attach to your exisiting Shopify navigation, meaning your store could have a menu makeover in minutes.


Related articles


2 ways developers build Shopify storefront apps and how they affect your theme


How to manually redirect customers after registration on Shopify


How to create sub-collections in Shopify with link lists