usethe23 usethe23 - 16 days ago 8
Twig Question

How can i split values with twig using filters

I have a value inside {{ phone }} that i want to split to be formatted as a phone number with twig filters

Example; inside {{ phone }} = '20304050', i want the output to be: '20 30 40 50'.

I found this example :

{% set splitArray = "20304050"|split('', 2) %}
{% set formattedString = splitArray|join(' ') %}


But it doesn't work with my value inside the brackets {{ phone }}

Answer

Found the solution

{{ phone|split('', 2)|join(' ') }}