简体   繁体   English

麻烦将变量放入变量

[英]trouble putting variable into the variable

I have many icons, with names icon1, icon2, icon3 and so on... which are coming from server 我有很多图标,它们的名称分别是icon1,icon2,icon3等,它们来自服务器

how can I make a forloop and set that icon NUMBER in a loop automatically?. 如何创建forloop并自动在循环中设置该图标NUMBER

I tried this: 我尝试了这个:

{% for i in "1234" %}
  {{icon}}{{forloop.counter}}
{% endfor %}

but this is not giving me what I want. 但这没有给我我想要的东西。 why cannot I do something like this: 为什么我不能做这样的事情:

{{ icon{{forloop.counter}} }},

but this is giving me error, saying it cannot parse the expression 但这给了我错误,说它无法解析表达式

I guess you are looking for concatenation of your icon variable and for loop counter. 我猜您正在寻找icon变量的串联和循环计数器。

{% for i in "1234" %}
 {% with c=forloop.counter|stringformat:"s" %}
  {{icon|add:c}}
 {% endwith %}
{% endfor %}

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

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