Answers.Body: <p>Assuming that you always want to add a space after every two digits, something like this using Twig's <a href="http://twig.sensiolabs.org/doc/filters/split.html" rel="noreferrer">split</a> and <a href="http://twig.sensiolabs.org/doc/filters/join.html" rel="noreferrer">join</a> filters should work:</p>
  
  <pre><code>{% set splitArray = "20304050"|split('', 2) %}
  {% set formattedString = splitArray|join(' ') %}
  </code></pre>
  
  <p>If you want a different format, like <code>203 04 050</code>, then you could use <a href="http://twig.sensiolabs.org/doc/filters/slice.html" rel="noreferrer">slice</a>:</p>
  
  <pre><code>{% set firstSeg = "20404050"|slice(0, 3) %}
  {% set secondSeg = "20404050"|slice(3, 2) %}
  {% set thirdSeg = "20404050"|slice(5, 3) %}
  
  {% set formattedString = firstSeg ~ ' ' ~ secondSeg ~ ' ' ~ thirdSeg %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-01T20:45:30.610Z
Answers.Text: What if we need to split it like this: 203 04 050
Answers.UserDisplayName: Alf Vestre
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-01T21:58:22.080Z
Answers.Text: Updated answer.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-01T20:25:04.320Z
Answers.LastActivityDate: 2014-10-01T21:58:16.557Z
Answers.LastEditDate: 2014-10-01T21:58:16.557Z
Answers.UserDisplayName: Brad Bell
Body: <p>Can an integer be formatted as a telephone number using Twig filters or other methods?</p>
  
  <p>I have looked at the 'number_format' filter but it seems to be limited to controlling the number of decimals and how to delimited thousands.</p>
  
  <p>Example; Integer variable from cms '20304050', output to HTML in twig like this: '20 30 40 50'.</p>
  
Tags: <templating>
Title: Can an integer be formatted as a telephone number using Twig?
ThreadText: # Can an integer be formatted as a telephone number using Twig?
  
  (Asked by: username_0 on 2014-10-01)
  
  Can an integer be formatted as a telephone number using Twig filters or other methods?
  
  I have looked at the 'number\_format' filter but it seems to be limited to controlling the number of decimals and how to delimited thousands.
  
  Example; Integer variable from cms '20304050', output to HTML in twig like this: '20 30 40 50'.
  
  **Tags:** templating
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-10-01. Score: 8 | Accepted answer
  
  Assuming that you always want to add a space after every two digits, something like this using Twig's [split](http://twig.sensiolabs.org/doc/filters/split.html) and [join](http://twig.sensiolabs.org/doc/filters/join.html) filters should work:
  
  ```
  {% set splitArray = "20304050"|split('', 2) %}
  {% set formattedString = splitArray|join(' ') %}
  
  ```
  
  If you want a different format, like `203 04 050`, then you could use [slice](http://twig.sensiolabs.org/doc/filters/slice.html):
  
  ```
  {% set firstSeg = "20404050"|slice(0, 3) %}
  {% set secondSeg = "20404050"|slice(3, 2) %}
  {% set thirdSeg = "20404050"|slice(5, 3) %}
  
  {% set formattedString = firstSeg ~ ' ' ~ secondSeg ~ ' ' ~ thirdSeg %}
  
  ```
  
  > **Comments:**
  > **username_0**: What if we need to split it like this: 203 04 050  
  > **username_1**: Updated answer.  
  
  ---
  
  