How do a loop n.times in Liquid templating using an existing for loop

风流意气都作罢 提交于 2019-11-30 14:01:04
Justin Niessner

You should be able to use a for loop with a range (n is the number of iterations):

{% for num in (1..n) %}

In some instances of Shopify Liquid, it may also work to use

{% for num in (1...n) %}

If like me you want to have a dynamic number that is not based upon a collection length or in-build var you can use includes and default values with capture to work wonders

{% capture count %}{{include.count|default:16}}{% endcapture %}
{% for num in (1...count) %}
    {{num}}
{% endfor %}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!