如何使用现有的for循环在Liquid模板中进行n次循环 [英] How do a loop n.times in Liquid templating using an existing for loop
本文介绍了如何使用现有的for循环在Liquid模板中进行n次循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在ruby中,我可以做n次,是否可以在Liquid标记中进行?
In ruby I can do n.times do, is it possible to do this in Liquid markup?
我当前的循环是:对于site.posts中的视频,我的目标是运行此循环2次.当前有4个对象将通过循环调用,但我希望有8个.我希望这很清楚!
My current loop is: for video in site.posts my goal is to run this loop 2 times. There are currently 4 objects that will be called through the loop but I want 8. I hope this is clear!
推荐答案
您应该能够在范围内使用for循环(n
是迭代次数):
You should be able to use a for loop with a range (n
is the number of iterations):
{% for num in (1..n) %}
在某些情况下,Shopify Liquid也可以使用
In some instances of Shopify Liquid, it may also work to use
{% for num in (1...n) %}
这篇关于如何使用现有的for循环在Liquid模板中进行n次循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文