I am currently concatenating array elements in a single variable with , between them. I'm getting record like this
abc,def,ghi,
I dont want to add an extra comma ,
after last element. My code is:
{% for driver in item.vehicles if driver.driver.firstName %}
{% set isDriver = 1 %}
{% set driverList = driverList ~ driver.driver.firstName ~ ',' %}
{% endfor %}
You can use the TWIG LOOP VARIABLE for your needed like this:
{% for 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 %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With