我有这个数组
{% set icons = { 1: 'glyphicon glyphicon-asterisk',
2: 'glyphicon glyphicon-plus',
3: 'glyphicon glyphicon-minus',
4: 'glyphicon glyphicon-euro'
}
%}
我想循环浏览它并像这样打印
<li{{ item.attributes.addClass('pos' ~ loop.index, icons[loop.index]) }}>
答案 0 :(得分:1)
像这样:
{% for key, value in icons %}
<li{{ item.attributes.addClass('pos' ~ key, value) }}>
{% endfor %}