How to format phone numbers in AnQiCMS templates, for example, adding country codes or separators?

Calendar 👁️ 64

In website operation, a clear, professional and easily recognizable phone number often leaves a deep impression on users and directly affects the conversion rate.For enterprises and content creators who rely on Anqi CMS to build websites, how to elegantly display contact information in templates, making it conform to local customs, adding country codes, or visual separators, is a key factor in improving user experience.AnQi CMS with its flexible Django template engine syntax and rich built-in filters provides us with powerful tools and methods to achieve this goal.

Obtaining and displaying phone numbers

In Anqi CMS, contact information such as phone numbers, which is a global contact, is usually managed through the 'Contact Information Settings' on the backend. Once set up in the backend, we can use the built-incontactLabel easily obtain this information. For example, to get the contact number configured in the background, we can call it like this:

{% set raw_phone = contact with name="Cellphone" %}
{{ raw_phone }}

This will directly output the original phone number you entered in the background, for example13800138000or010-88888888However, the original number often needs further processing to meet specific display requirements.

Formatting strategy one: add country code

At times, especially for websites aimed at international users, we need to add country codes to phone numbers to help users identify and dial them more clearly. Assuming our website mainly serves Chinese users, the area code is+86We can cleverly utilizeaddThe filter to concatenate strings.

addThe filter can concatenate two strings or numbers. To make its application more flexible, we usually assign the original phone number to a variable first, and then combine it with the area code prefix:

{% set raw_phone = contact with name="Cellphone" %}
{{ "+86 " | add: raw_phone }}

By this line of code, regardless of the background'sCellphonefield content is, for example13800138000, the front end will display as+86 13800138000. You can adjust it according to your actual needs, to+86Replace with any country code you need, and note the space or hyphen between the area code and the number.

Formatting strategy two: add separators to enhance readability.

Phone numbers often need to use separators to improve readability, for example, to separate13800138000Formatted as138-0013-8000This usually involves two steps: first, cleaning up any non-numeric characters that may be present in the number, and then inserting new separators according to specific rules.

1. Clean non-numeric charactersBefore formatting a phone number, it is a good practice to remove all possible non-numeric characters, such as spaces, parentheses, hyphens, etc., to ensure that we are working with a pure numeric string.replaceThe filter is the ideal tool for this task. You can chain it to remove multiple characters:

{% set raw_phone_input = contact with name="Cellphone" %}
{% set cleaned_phone = raw_phone_input | replace:"-","" | replace:" ","" | replace:"(","" | replace:")","" %}

Now, `cleaned

Related articles

Does AnQiCMS provide a feature for batch updating or synchronizing contact information to all child sites?

As an experienced website operations expert, I know how important efficiency and consistency are when managing multiple sites.Especially for enterprises with multiple brands, sub-sites, or content branches, how to efficiently maintain core information such as contact details is an indispensable topic in daily operations.Today, let's delve into the performance of AnQiCMS (AnQiCMS) in the function of 'batch updating or synchronizing contact information to all child sites'.First, let's clarify the core design philosophy of AnQi CMS in terms of multi-site management.Based on the documents at hand

2025-11-06

How to ensure the uniformity and independence of contact information between multiple sites and avoid data confusion?

AnQiCMS's excellent performance in multi-site management allows content operators to easily manage multiple brands or projects without getting lost in a sea of information.How to cleverly handle the contact methods between different sites, ensuring the uniqueness of each site while also realizing the unified display of certain information to avoid data confusion is a focus of many operators.As an experienced website operation expert, I will deeply analyze this strategy by combining the characteristics of AnQiCMS.

2025-11-06

Can different AnQiCMS sub-sites set completely independent contact information sets?

As an expert deeply familiar with website operations, especially one who has been deeply involved in the AnQiCMS platform for many years, I am very happy to discuss with everyone a common yet crucial issue: 'Can different AnQiCMS sub-sites set up completely independent contact information sets?'}]This question is directly related to the flexibility and efficiency of website operations for enterprises that need to manage multiple brands, multiple regional businesses, or have different product lines.

2025-11-06

What is the specific usage method of the `siteId` parameter in the `{% contact %}` tag?

In AnQiCMS's powerful feature system, multi-site management is undoubtedly a highlight, making it easy for enterprises and operators to deal with the complex needs of multiple brands, sub-sites, or content branches.In our daily website template development and content operations, the `{% contact %}` tag is a powerful helper for displaying website contact information.

2025-11-06

How to truncate the contact address field in the template while retaining the complete information?

As an old soldier who deeply understands the way of CMS content operation, I know that every detail in website construction and content presentation is related to user experience and brand image.Especially when displaying key elements such as contact information, how to ensure beauty and cleanliness in a limited space while fully conveying the information, this is often a small challenge faced by operators.Today, let's delve deeply into how to cleverly truncate the display of the contact address field in the Anqi CMS template when it is too long, while ensuring that users can always obtain the complete address information.Challenge

2025-11-06

How to implement responsive layout and optimize loading speed for WeChat QR code images in AnQiCMS template?

As an experienced website operation expert, I am well aware that in today's multi-device environment, the display effect and loading speed of website content are key factors determining user experience and search engine performance.The WeChat QR code is an important tool for connecting online and offline and promoting user conversion, and its presentation in the AnQiCMS template also requires fine-tuning.Today, let's delve into how to achieve a perfect responsive layout and optimize loading speed for your WeChat QR code image in AnQiCMS templates, providing a smooth user experience.

2025-11-06

Do I support automatically adding `tel:` and `mailto:` links to contact numbers and email addresses, AnQiCMS?

In today's website operations, improving user experience and convenience is one of the core competitive advantages.When a user sees a phone number or email address on a website and can directly click to dial or send an email, it undoubtedly greatly improves efficiency and satisfaction.So, does AnQiCMS (AnQi Content Management System) support automatically adding `tel:` and `mailto:` links to the contact phone numbers and email addresses on the website?As an experienced website operations expert, I can confidently tell you that AnQiCMS provides a flexible mechanism to meet this requirement

2025-11-06

How to make all external links output by AnQiCMS contact information tags automatically add the `rel="nofollow"` attribute?

As an experienced website operations expert, I fully understand your attention to the details of website SEO, especially the handling of external links.In AnQiCMS, to automatically add the `rel="nofollow"` attribute to all external links output by the contact information label, this involves understanding the core function mechanism of the CMS and also requires some flexible template application skills.First, let's delve into the meaning of the `rel="nofollow"` attribute.This attribute tells the search engine not to consider this link as an 'endorsement' or 'vote' for the target website

2025-11-06