我正试图在jinja2中制作一个mod,但没办法.
{%set index = 1%}
选项1:
{% for .... %}
{% if {{index % 3 == 0}} %}
{% endif %}
{% set index = index + 1 %}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
选项2:
{% for .... %}
{% if index.index is divisibleby 3 %}
{% endif %}
{% set index = index + 1 %}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
任何的想法?
谢谢
您只需要从第一个if语句中删除{{}}即可.这段代码有效......
<!-- {% set index = 9 %} -->
{% set index = 10 %}
{% if index % 3 == 0 %}hi
{% endif %}
{% set index = index + 1 %}
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!
小智 5
您可以使用batch过滤器:
{% for itens_batched in itens|batch(3) %}
{% for item in itens_batched %}
{% endfor %}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
http://jinja.pocoo.org/docs/dev/templates/#batch
| 归档时间: |
|
| 查看次数: |
12450 次 |
| 最近记录: |