使用 Twig 或 Swig 的 for 循环计数器计数器、Twig、Swig、for

2023-09-07 00:36:25 作者:孤痞成性

任何人都知道在 Twig/Swig 中执行此操作的干净方法:

Anyone know of a clean way to do this in Twig/Swig:

{% for(i = 0; i < 100; i++) %}
    blah....
{% endfor %}

推荐答案

对于twig其:

{% for i in 0..100 %}
    * {{ i }}
{% endfor %}

来自 http://twig.sensiolabs.org/doc/tags/for.html

对于 swig,文档还没有提到它:https://github.com/paularmstrong/swig/blob/master/docs/tags.md#for

For swig the docs dont mention it yet: https://github.com/paularmstrong/swig/blob/master/docs/tags.md#for

我真的不能说,但它可能在 swig 中不受支持,因为它的 django 灵感和 django 似乎也天生缺乏这个功能:https://code.djangoproject.com/ticket/5172

i cant really tell but it might be not supported in swig since its django inspired and django also seems to lack this feature nativly: https://code.djangoproject.com/ticket/5172

所以我想将痛饮部分传递给下一个.

so i would like to pass the swig part to the next one.