Reputation: 87
I am fetching some results from database through doctrine.
The resulting array for e.g. ads.attraction
has strings (words) with commas inside.
How can I separate each word from the comma and display each of them on it's own line?
Upvotes: 3
Views: 3906
Reputation: 52493
The twig split filter converts a string to an array by given delimiter.
Afterwards you can output each element of this array using a for
loop.
{% set array = "one,two,three"|split(',') %}
{% for element in array %}
{{ element }}<br />
{% endfor %}
Just replace "one,two,three"
with your variable (ads.attraction
) in your concrete case.
Upvotes: 12