假设我在数组中将一些名为"people"的数据转换为这样的树枝模板:
firstname | surname | colour Fred Smith Blue James Holmes Red Sarah Fisher Blue Chrstine Jenkins Yellow Sid Wells Red Cory Simpson Blue Laura Jones Yellow
有了这些数据,我需要通过"颜色"列对它们进行分组.通过基于颜色包裹用户周围的div.例如
Fred Smith - Blue
Sarah Fisher - Blue
Cory Simpson - Blue
James Holmes - Red
Sid Wells - Red
Christine Jenkins - Yellow
Laura Jones - Yellow
现在如果我使用一个twig循环,它会将div放在每个名称周围,而不是按颜色对它们进行分组.什么是获得上述输出的最简单方法?我已经在循环中尝试了各种各样的东西,但我正在努力.
{% for p in people %}{{ p.firstname }} {{ p.surname }} - {{ p.colour }}{% endfor %}
我需要它以某种方式循环遍历唯一的颜色值,然后循环遍历属于该颜色的名称.