[英]Symfony2, how can I skip printing repeated values in a loop in twig templates?
我在此循环中有一张桌子:
{% for key, value in boxes %}
<tr>
<td>{{ value.boxnum }}</td>
<td>{{ value.code }}</td>
<td>{{ value.total }}</td>
<td>{{ value.qty }}</td>
</tr>
{% endfor %}
给出了以下表格:
Box Code Total Qty
3096362 130291 27 216
3096362 140001 18 144
3096362 140003 4 32
3096362 140013 14 112
我如何才能使Box#列仅打印一次,因为其余的只是重复一次?
这就是你可以做的
{% set bnum = '' %}
{% for key, value in boxes %}
<tr>
{% if bnum != value.boxnum %}
{% set bnum = value.boxnum %}
<td>{{ value.boxnum }}</td>
{% else %}
<td></td>
{% endif %}
<td>{{ value.code }}</td>
<td>{{ value.total }}</td>
<td>{{ value.qty }}</td>
</tr>
{% endfor %}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.