Perch Template filter for converting Telephone Numbers

  • Hello,

    I frequently need to convert a telephone number to a <href="tel:..." friendly format.

    Currently I do this in php on every single page that requires it eg:

    Does anyone know how I could do this using a perch template filter? To enable something like:

    1. <perch:content type="text" id="tel" filter="formatted"/>

    PHP isn't my strong point, so whilst I don't necessarily need a finished filter as the answer (but feel free) a basic example to get me going would be great.

  • I think I've worked it out - this goes in the /perch/addons/templates/filters.php file:

    The tag then looks like:

    1. <perch:content type="text" id="tel" filter="formattedNo"/>

    Typical use case:

    1. Tel: <a href="tel:<perch:content type="text" id="tel" filter="formattedNo"/>" title="Call us on <perch:content type="text" id="tel" />"><perch:content type="text" id="tel" /></a>