How to render formatted phone_number in Twig

Created on 29 April 2019, over 5 years ago
Updated 3 March 2023, almost 2 years ago

I have an entity with an entity reference to another entity that has a phone_number field. I am trying to display the formatted phone number in the first entity's template, but I can't seem to get the formatting.

Here is how I am accessing the phone number:

{{ content.field_entity_reference.entity.field_phone_number }}

This throws a Twig error.

I entered the phone number in this format +1 (ddd) ddd-dddd, which is how I would like to display the phone number, but I can't figure out how to get my formatting back out of the field.

field_phone_number.0 has these keys:

  • value
  • country
  • local_number
  • extension

field_phone_number.0.value just returns +1dddddddddd, without any formatting.

So, what I am wondering is there an easy way to get the formatting at the theme layer? Do I need to use the phone_number.util service?

πŸ’¬ Support request
Status

Closed: works as designed

Version

1.0

Component

Documentation

Created by

πŸ‡ΊπŸ‡ΈUnited States scottsawyer Atlanta

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024