How to split a string into an array How can I split (or explode) a Twig string like this:

{% set fruits = "Apples; Bananas; Tomatoes" %}


into an array like this:

{{ ["Apples", "Bananas", "Tomatoes"] }}
You would use the split filter.

{% set fruits = "Apples; Bananas; Tomatoes" | split('; ') %}