symfony - How to check if array has more elements in twigs for loop? -
i concatenating array elements in single variable , between them. i'm getting record this
abc,def,ghi,
i dont want add comma ,
after last element. code is:
{% driver in item.vehicles if driver.driver.firstname %} {% set isdriver = 1 %} {% set driverlist = driverlist ~ driver.driver.firstname ~ ',' %} {% endfor %}
you can use twig loop variable needed this:
{% driver in item.vehicles if driver.driver.firstname %} {% set isdriver = 1 %} {% set driverlist = driverlist ~ driver.driver.firstname %} {% if loop.last == false %} {% set driverlist = driverlist ~ ',' %} {% endif %} {% endfor %}
Comments
Post a Comment