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
-%}
Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024In today’s interview, we sat down with @BSS-Commerce to discuss practical strategies f...
By JasonH Nov 13, 2024