This is a Perch template filter for formatting phone numbers. The phone filter uses libphonenumber-for-php, a library based on Google's libphonenumber, for formatting and validating phone numbers.
- Download the latest version
- Place the
pipit_phonedirectory in the folderperch/addons/templates/filters/ - Include the class in the file
perch/addons/templates/filters.php:
include('filters/pipit_phone/PipitTemplateFilter_phone.class.php');You need to enable template filters in your config file perch/config/config.php:
define('PERCH_TEMPLATE_FILTERS', true);You can set a default country to format the numbers to its standards:
define('PIPIT_PHONE_COUNTRY', 'GB');<a href="<perch:content id="phone_number" filter="phone" country="gb" output="tel_link">" >
<perch:content id="phone_number" filter="phone" country="gb" output="international">
</a>If you have defined a default country PIPIT_PHONE_COUNTRY in your Perch configuration, you can omit the country attribute:
<a href="<perch:content id="phone_number" filter="phone" output="tel_link">" >
<perch:content id="phone_number" filter="phone" output="international">
</a>| Attribute | Description |
|---|---|
| country | The country of the phone number. Takes a two-letter country code ISO 3166 |
| output | The formatting option to be used to output the phone number. See table below. Omitting the attribute will output the phone number with no spacing. |
| Option | Description |
|---|---|
| international | International formatting of the phone number |
| national | Nationaly formatting of the phone number |
| tel_link | The phone number formatted for tel URI - RFC3966 (prefixed with tel:) |