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

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -