I have a simple array of floats. And I need to show it as comma separated string.
{{ arr|join(', ') }}
is bad solution because of excessive insignificant accuracy.
{% for val in arr %}
{{val|number_format(2)}},
{% endfor %}
is bad because of extra comma at the end.
I would like to do something like this:
{{ arr|map(number_format(3))|join(', ') }}
but I have not found filter map
or similar filter it Twig.
Аnd I don't know how to implement such filter.
Why not use the loop
variable?
{% for val in arr %}
{{val|number_format(2)}}
{% if not loop.last %}, {% endif %}
{% endfor %}
BEFORE
into AFTER
(uppercase first letter){%- set mylist = ['alpha','bravo','charlie','delta','echo'] -%} BEFORE: ['alpha','bravo','charlie','delta','echo'] AFTER: ['Alpha','Bravo','Charlie','Delta','Echo']
{%- set mylist = mylist|map(=> _|capitalize) -%}
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