In the operation of daily websites, we often encounter situations where we need to process various types of data and display it in a user-friendly manner.A phone number is a typical example. Sometimes, for marketing or brand promotion, we may see some 'vanity numbers' composed of letters and numbers, such as '1-800-FLOWERS'.These numbers are easy to remember, but users still need to manually convert them to pure numbers when dialing.
AnQi CMS as a feature-rich enterprise-level content management system fully considers these details needs. It provides a very practical built-in filter——phone2numericIt can easily help us automatically convert the letters on the mobile phone keyboard to the corresponding numbers, so that when displayed on the website front-end, it can both retain the creativity of the number and make it convenient for users to identify and dial directly.
phone2numericThe core function of the filter and the conversion rules
phone2numericThe design inspiration of the filter comes from the familiar traditional mobile phone keyboard.Each number key usually corresponds to a few letters, and this filter is based on this standard mapping relationship for conversion.It only handles English letters, converting them to their corresponding numbers;And for numbers, hyphens, or other non-letter characters, they will be retained as is.
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
Useful scenario analysis: How to leveragephone2numericEnhancing user experience
This seemingly simple feature can be put to good use in actual operations:
Marketing and brand promotion: Display letters and numbers at the same timeIf your brand phone number is a combination of letters and numbers, for example
1-800-ANQICMSYou may wish to display this memorable letter combination on the website as well as clearly provide its corresponding numeric form. Byphone2numericFilter, you can easily achieve this goal. The user can see the letter number at the same time and recognize its numeric form at a glance, which greatly reduces the dialing threshold.Simplify user memory and dialing: Intuitive dialing guidanceFor some users who are not familiar with the letter-number correspondence on mobile phone keyboards, or in emergencies, seeing the phone number in pure numeric form is undoubtedly more efficient.By using 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.
Flexibility in data display: Seamless connection between backend storage and frontend presentationSometimes, in the Anqi CMS backend content model, you may want to store some phone numbers in alphabetical form for easy management and identification.But when displaying on the front-end page, for universality and user-friendliness, it also needs to be converted to a number.
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 a pipe|to connect variables with filters.
Assuming you have a variablemyPhoneNumberstored like"999-PONGO2"Such a string, do you want to convert it to a numeric form and display it on the page?
Basic usage as follows:
{{ myPhoneNumber|phone2numeric }}
Specific examples:
If you have set up a custom field in the backgroundvanityNumberThe value is stored as"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 as:
<p>我们的服务热线(字母形式):800-HELPCMS</p>
<p>我们的服务热线(数字形式):800-4357267</p>
<p>营销电话:999-PONGO2 (请拨打 999-766462)</p>
As you can see,phone2numericThe filter has accurately converted the letter part into the corresponding numbers, while retaining the numbers and hyphens in the original string, making the output clear and easy to understand.
Summary
Of Security CMSphone2numericThe filter is a small feature that brings great convenience. It intelligently converts the letters on the phone keyboard to numbers, greatly enhancing the flexibility and user-friendliness of displaying phone numbers on websites.In order to enhance marketing effectiveness, simplify user operations, or for the convenience of backend data management, this filter is an indispensable member of your website's operation toolset.
Frequently Asked Questions (FAQ)
1.phone2numericDoes the filter convert numbers or non-letter characters?No.phone2numericThe filter only recognizes and converts English letters. For any numbers, hyphens, spaces, or any other non-letter characters in the original string, it will retain them as they are and make no changes.
2.phone2numericCan the letter-number mapping relationship of the filter be customized?According to the current design of Anqi CMS,phone2numericThe filter uses the standard mobile keyboard letter-number mapping, which is fixed and does not support user customization.It aims to provide a general, widely recognized transformation standard.
3. If entered intophone2numericWhat will be the result if the filter's string is empty?If input tophone2numericThe string in the filter is empty (for example{{ ""|phone2numeric }}), the output will also be an empty string, no errors or unexpected content will occur.