Loops 转到下一个参数细枝

Loops 转到下一个参数细枝,loops,twig,Loops,Twig,我对Twig是新手,我想知道如何转到循环中的下一个值 这是一个简单的例子: {% for user in users %} <table> <tr> <td> {{ user.username }} </td> <td> {# here i want to prin

我对Twig是新手,我想知道如何转到循环中的下一个值

这是一个简单的例子:

{% for user in users %}
        <table>
          <tr>
            <td>
                {{ user.username }}
            </td>

            <td>
                {# here i want to print the next username in the same line of the table #}
            </td>
          </tr>
        </table>
    {% endfor %}
谢谢你的帮助 对不起,我的英语不好

我相信你能做到

{{ user[loop.index + 1].username }}

中有一些关于循环变量的进一步信息,请确保在显示下一个变量之前检查用户是否不是最后一个

{% for user in users %}
<table>
     <tr>
          <td>
           {{ user.username }}
          </td>
          <td>
               {% if not loop.last%}
                    {{ users[loop.index0 + 1].username }}
               {%endif%}
          </td>
     </tr>
</table>
{% endfor %}

这不是数组,它是SELECT语句的结果。这对我不起作用@BaHarAyØub没有使用{users[loop.index+1].username}}}user'S,因为必须将数组指向本地user@BaHarAyØub select语句的结果要么是数组,要么是对象-无论哪种方式,根据我的示例可以访问它这是我在对象中获得的键2,具有类型为\Arkiglass\ProduitBundle\Entity\Produit的数组访问在ArkiglassProduitBundle中不存在:Site:Produit.html.twig第43行是新的指令用户[loop.index+1].用户名,我确信在显示下一个用户之前,该用户不是最后一个。您有多少个产品?您的用户实体中是否有返回数组的getProduit方法?@BaHarAyØub allso trie with loop.index0从0而不是从1获取索引