简体   繁体   English

Twig 基于 integer 值生成

[英]Twig generate <td> in <tr> based on an integer value

search over this in google and looked the official docs of twig, didn't find an answer,在谷歌中搜索这个并查看 twig 的官方文档,没有找到答案,

I have this我有这个

  $data['count'] = $count;//6

in my php code, I want to generate td as much as the $beltCount in the twig file I tried this but it didn't work:在我的 php 代码中,我想生成与 twig 文件中的 $beltCount 一样多的 td 我试过这个,但它没有用:

{% for i in count%}
  <td> {{ i }}</td>
{% endfor %}

Should I do this in a different way?我应该以不同的方式做到这一点吗? I didn't find a syntax for this我没有找到这个的语法

Thanks谢谢

The integer 6 isn't enumerable, it's just a number. integer 6 不可枚举,它只是一个数字。

You can however use range(1, count) or, as stated Teneff in comments, the range operator 1..count to create an enumerable from 1 to 6 (or whatever value is in count ):但是,您可以使用range(1, count)或如Teneff在评论中所述,范围运算符1..count来创建一个从 1 到 6 的可枚举(或count中的任何值):

{% for i in range(1, count) %}
  <td> {{ i }}</td>
{% endfor %}

{% for i in 1..count %}
  <td> {{ i }}</td>
{% endfor %}

fiddle小提琴

You will find more infos in the documentation您将在文档中找到更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM