Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi,
I'm trying to do something quite simple, well, I think it's simple, but struggling!
I am making a rating system where I am using a font awesome icon. All I want to do is pass a given number, say 3, to then render out that icon out 3 times.
My usual attack would be to do new Array(3) then iterate over it. But I can't seem to find a way to do this in Liquid.
Any ideas?
Many thanks.
Solved! Go to the solution
This is an accepted solution.
Hi @navster, I assume you want to iterate using loops, please have a look at the following code.
{% for i in (1..5) %} <!-- Your code will be here --> {% endfor %}
Or if want to use an array, check the following example code
{% assign array = [1,2,3] %} {% for item in array %} {{ item }} {% endfor %}
This is an accepted solution.
Hi @navster, I assume you want to iterate using loops, please have a look at the following code.
{% for i in (1..5) %} <!-- Your code will be here --> {% endfor %}
Or if want to use an array, check the following example code
{% assign array = [1,2,3] %} {% for item in array %} {{ item }} {% endfor %}
Ahh that's spot on mate - thank you! I was not aware of the 1..x syntax.
Thanks again 🙂
Here is a succinct way to render snippets (which could contain icons) iteratively:
{%- liquid
assign upsells = section.blocks | where: 'type', 'upsell'
render 'block-product-upsell' for upsells as upsell
-%}
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025