任何人都知道在 Twig/Swig 中执行此操作的干净方法:
{% for(i = 0; i < 100; i++) %}
blah....
{% endfor %}
最佳答案
如果您有一个数字,那么您可以将其转换为一个数组,然后使用 Swig 的标准作为标记。如果您总是想从 0 开始“开始”循环,这是最简单的。
例如:
{% set productCount = 6 %}
{% set productCountAsArray = Array(productCount) %}
{# This will run productCount times #}
{% for x, y in productCountAsArray %}
This is for number: {{ x }}
{% endfor %}
关于node.js - for 循环计数器与 Twig 或 Swig,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12102742/