In daily website operation, we often encounter situations where we need to handle various types of data and present them in a user-friendly manner.A telephone number is a typical example.Sometimes, for marketing or brand promotion, we might see some 'vanity numbers' composed of letters and numbers, such as '1-800-FLOWERS'.This number is easy to remember, but users still need to manually convert it to pure digits when dialing.

AnQi CMS, as a feature-rich enterprise-level content management system, fully considers these detailed requirements. It provides a very practical built-in filter.phone2numericIt can help us easily convert the letters on the phone keyboard to the corresponding numbers, thus, when displaying on the website front-end, it can preserve the creativity of the number and make it convenient for users to directly identify and dial.

phone2numericThe core function of the filter and conversion rules

phone2numericThe design inspiration of the filter comes from the familiar traditional mobile phone keyboard.Each digit key usually corresponds to several letters, and this filter is based on this standard mapping relationship for conversion.It only handles English letters, converting them to the corresponding numbers; while for numbers, hyphens, or other non-letter characters, they are retained as they are.

The specific conversion rules are as follows:

  • 2Corresponding letters: A, B, C
  • 3Corresponding letters: D, E, F
  • 4Corresponding letters: G, H, I
  • 5Corresponding letters: J, K, L
  • 6Corresponding letters: M, N, O
  • 7Corresponding letters: P, Q, R, S
  • 8Corresponding letters: T, U, V
  • 9Corresponding letters: W, X, Y, Z

实用场景解析:如何借助 Englishphone2numericEnhance user experience

这个看似简单的功能,在实际运营中却能派上大用场: English

  1. 营销与品牌推广:同时展示字母与数字号码 EnglishIf your brand phone number is a combination of letters and numbers, for example1-800-ANQICMSYou may wish to display this memorable letter combination on the website while also clearly providing its corresponding numeric form.phone2numericFilter, you can easily achieve this goal. Users can recognize the number letters at the same time and also easily identify their numeric forms, greatly reducing the calling threshold.

  2. Simplify user memory and dialing: Intuitive dialing guidanceFor users who are not familiar with the correspondence between letters and numbers on the phone keyboard, or in emergencies, seeing the phone number in pure numeric form is undoubtedly more efficient.Through the use of this filter on the contact page, footer, or specific promotional areas, you can provide users with a more intuitive and convenient dialing guide, reducing their trouble of manual conversion.

  3. Flexibility in data display: Seamless connection between backend storage and frontend presentationSometimes, in the backend content model of AnQi CMS, you may want to store some phone numbers in alphabetical form for easy management and identification.But when displaying on the front-end page, it is necessary to convert it to a number for universality and user-friendliness.phone2numericThe filter perfectly meets this requirement, ensuring the diversity of backend data and the standardization of frontend display.

How to use in Anqi CMS templatephone2numericFilter

Application in Anqi CMS templatephone2numericThe filter is very simple, it follows the syntax rules of the Django template engine, with the pipe character|Connecting variables with filters.

Suppose you have a variablemyPhoneNumberStored like"999-PONGO2"This string, you want to convert it to a numeric form and display it on the page.

Basic usage is as follows:

{{ myPhoneNumber|phone2numeric }}

Specific examples:

If you have set a custom field in the backgroundvanityNumberEnglish, storage value is"800-HELPCMS"And call it on the page:

{# 假设 myPhoneNumber 变量的值是 "800-HELPCMS" #}
<p>我们的服务热线(字母形式):{{ myPhoneNumber }}</p>
<p>我们的服务热线(数字形式):{{ myPhoneNumber|phone2numeric }}</p>

{# 另一个示例,直接使用字符串常量 #}
<p>营销电话:999-PONGO2 (请拨打 {{ "999-PONGO2"|phone2numeric }})</p>

This code will be displayed on the page:

<p>我们的服务热线(字母形式):800-HELPCMS</p>
<p>我们的服务热线(数字形式):800-4357267</p>

<p>营销电话:999-PONGO2 (请拨打 999-766462)</p>

As you can see,phone2numericThe filter has accurately converted the alphabetical part into the corresponding numbers, while retaining the numbers and hyphens in the original string, making the output clear and easy to understand.

Summary

Anqi CMS'sphone2numericFilter is a small but convenient feature.It greatly enhances the flexibility and user-friendliness of displaying phone numbers on websites by intelligently converting the letters on the phone keyboard to numbers.Whether it is to enhance the marketing effect, simplify user operations, or for the convenience of backend data management, this filter is an indispensable member of your website's toolset.


Common Questions (FAQ)

1.phone2numericDoes the filter convert numbers or non-letter characters?No.phone2numericFilter only identifies and converts English letters. For any digits, hyphens, spaces, or any other non-letter characters in the original string, it will retain them unchanged, making no modifications.

2.phone2numericThe letter-number mapping relationship of the filter can be customized?According to the current design of the Anqi CMSphone2numericThe filter uses the standard mobile keyboard letter-number mapping relationship, which is fixed and does not support user customization.It aims to provide a universal, widely recognized standard for conversion.

3. If input tophone2numericThe filter string is empty, what will be the result?If input tophone2numericthe filter string is empty (for example{{ ""|phone2numeric }}) the output will also be an empty string, and no errors or unexpected content will occur.