How to dynamically display contact information in website templates?

Calendar 👁️ 76

When operating a website, we often need to display the company's contact information, such as phone, email, address, and even social media links.The traditional way may be to hard-code this information directly in the template, but this way, every time the contact information changes, you need to modify the code, which is麻烦 and easy to make mistakes.

AnQiCMS provides a flexible and efficient solution that allows you to easily display and manage these contact methods in website templates.This means that once the contact information changes, you only need to update it once in the background, and all the places on the website that use this information will be automatically synchronized, greatly improving operational efficiency.

Background settings for contact information

All website contact information is concentrated in the "Anqi CMS" backend of all websitesBackend settingsIn the module. After logging in to the background, find the menu on the left.Backend settingsthen click onContact information settingsAs soon as

You will see some preset contact information fields, such as:

  • Contact: It is usually the name of the company or the main contact person.
  • Contact phone numberThe main contact phone number of the company.
  • Contact addressThe actual office address of the company.
  • Contact emailThe email address used for business communication.
  • WeChat ID/WeChat QR codeConvenient for users to contact through WeChat.
  • QQ/WhatsApp/Facebook/Twitter/TikTok/Pinterest/LinkedIn/Instagram/YouTubeThese cover mainstream social media platforms both domestically and internationally, making it convenient for you to promote globally.

If these built-in fields do not meet your needs, for example, if you need to add a specific department contact phone number, or a less commonly used social media link, Anqi CMS also provides the function of custom settings. Simply click on "Custom Settings Parameters", then fill in:

  • Parameter NameThis is the name you use when calling the template, it is recommended to use English, the system will automatically convert it to camel case. For example, you can setSalesEmailorSupportPhone.
  • Parameter valueThis is the actual contact information, such as[email protected].
  • Note: It is convenient for you to identify the use of this parameter, it will not be displayed on the website front end.

In this way, you can flexibly add, modify, and manage various contact methods according to the actual needs of the website.

Dynamically call contact information in the website template.

After setting up the contact information in the background, you can use the Anqicms in the website templatecontacttags to dynamically display this information. This tag is very intuitive, and its basic usage is:

{% contact 变量名称 with name="字段名称" %}

Among them:

  • 变量名称Optional, you can give the obtained data a temporary name for easy reference in the code. If this part is omitted, the tag will directly output the value of the field.
  • name="字段名称"It is crucial, you need to specify the field name of the contact information you want to call, such asCellphone/EmailOr you can customize itWhatsApp.

We will go through some common examples to see how to use it in templates:

1. Display contact phone number

You can display the company's contact phone number at the top, bottom, or on the 'Contact Us' page. For convenience, we can also wrap it in atel:link.

<p>电话:<a href="tel:{% contact with name='Cellphone' %}">{% contact with name='Cellphone' %}</a></p>

2. Display contact email

Similar to a phone number, an email address can also be made clickablemailto:links.

<p>邮箱:<a href="mailto:{% contact with name='Email' %}">{% contact with name='Email' %}</a></p>

3. Display the company address

Address information is usually displayed in the footer or contact page

<p>地址:{% contact with name='Address' %}</p>

4. Display the WeChat QR code

If your website needs to display a WeChat QR code, you can do so byQrcodeusing the field to call the image uploaded to the backend.

<div class="wechat-qrcode">
    <img src="{% contact with name='Qrcode' %}" alt="微信二维码" />
    <p>扫描微信二维码联系我们</p>
</div>

5. Call the custom WhatsApp account

Assuming you have customized a name in the backgroundWhatsAppfor the contact information, you can call it like this:

<p>WhatsApp:<a href="https://wa.me/{% contact with name='WhatsApp' %}" target="_blank">{% contact with name='WhatsApp' %}</a></p>

Here we combined the official WhatsApp link format to allow users to directly jump to chat.

6. Multi-site contact information call

If your Anqicms CMS has deployed multiple sites (through the multi-site management feature), and you want to display the contact information of *other* sites in the template of the current site, you cancontactAdd in the labelsiteIdSpecify the site ID with parameters. For example, if a site with ID 2 has a specific contact phone number, you can call it like this:

<p>分公司电话:<a href="tel:{% contact with name='Cellphone' siteId=2 %}">{% contact with name='Cellphone' siteId=2 %}</a></p>

Practical scenarios and advanced skills

Flexible combination displayBy combining differentcontactLabel, you can display the contact information you need flexibly at any location on the website, such as the footer, sidebar, or pop-up window.

<footer>
    <p>联系人:{% contact with name='UserName' %}</p>
    <p>电话:<a href="tel:{% contact with name='Cellphone' %}">{% contact with name='Cellphone' %}</a></p>
    <p>邮箱:<a href="mailto:{% contact with name='Email' %}">{% contact with name='Email' %}</a></p>
    <p>地址:{% contact with name='Address' %}</p>
    <div class="social-links">
        {% if contact.Facebook %}
            <a href="{% contact with name='Facebook' %}" target="_blank">Facebook</a>
        {% endif %}
        {% if contact.Twitter %}
            <a href="{% contact with name='Twitter' %}" target="_blank">Twitter</a>
        {% endif %}
    </div>
</footer>

Handle null valuesTo avoid blank or unattractive text appearing on the page when some contact information is empty, you can make a judgment before displaying it. CombineifLogical judgment tags anddefaultThe filter can make the template more robust.

{% if contact.Cellphone %}
    <p>电话:<a href="tel:{% contact with name='Cellphone' %}">{% contact with name='Cellphone' %}</a></p>
{% else %}
    <p>电话:暂无</p>
{% endif %}

{# 或者使用default过滤器提供默认值 #}
<p>电话:{% contact with name='Cellphone' %}|default:"暂无联系电话"</p>

Of Security CMScontactTags bring great convenience and flexibility to website contact information management.By simple backend configuration and template calls, you can build dynamic, easy to maintain, and user-friendly websites.No longer need to worry about frequently modifying the code due to changes in contact information.

Related articles

How to flexibly call the system global configuration information for display in the website template?

Flexibly calling the system global configuration information in the website template is a key step in building a dynamic and easy-to-maintain website.AnQiCMS (AnQiCMS) fully understands this need and therefore provided powerful and intuitive template tags from the outset, allowing users to easily display preset system-level data, contact information, and even customized information at any position on the page.The Anqi CMS template system adopts a syntax similar to the Django template engine, where variables are usually defined using double curly braces `{{ variable_name }}`, and various operations and tags are through single curly braces and percent signs

2025-11-08

How does AnQiCMS improve the loading speed and display experience of website content through static caching?

In today's fast-paced digital world, the loading speed of websites and user experience are crucial.A fast-reacting website can not only effectively retain visitors but also improve search engine rankings and bring more exposure to the content.AnQiCMS, as an enterprise-level content management system developed based on the Go language, has always regarded high performance as one of its core goals from its initial design, and has significantly improved the speed of website content loading and display experience through this key technology of static caching.Static caching, in simple terms, is the process of pre-generating static HTML files for a website's dynamic content

2025-11-08

How to configure resource storage and backup to ensure the security and recoverability of website content?

In daily website operations, the security and recoverability of content are of great importance.Imagine if your website data suddenly disappeared, or if important images failed to display, how much trouble it would cause for operations.AnQiCMS (AnQiCMS) is an efficient content management system that provides many functions to help us manage website resources properly and ensure quick recovery in case of emergencies.This article will delve into how to configure the resource storage and backup mechanism of Anqi CMS to maintain the continuous stable operation of the website.### One

2025-11-08

How to use the scheduled publishing feature to control articles to be automatically displayed at a future time?

In content operation, the rhythm and timing of content release are often the key factors determining its effectiveness.Imagine that you have carefully prepared a series of contents, hoping that they will appear on the website at a specific time, such as 9 am every morning, or automatically go online before the upcoming festival activities.Manual operation is not only inefficient but also prone to errors. AnQiCMS (AnQiCMS) understands this need and provides a convenient scheduling publishing function, allowing you to easily plan future content and achieve automated operations.Schedule release

2025-11-08

How to set independent TDK (title, description, keywords) for the homepage of a website to optimize search results display?

How to make your website stand out among a vast amount of information and gain more exposure in website operation?In this case, Search Engine Optimization (SEO) plays a vital role, and the title (Title), description (Description), and keywords (Keywords), which we commonly refer to as TDK, are the cornerstone of SEO strategy.For users of AnQiCMS, setting up independent homepage TDK is not only simple and efficient, but also a key step in optimizing website search performance.Why is the TDK setting on the homepage crucial

2025-11-08

How to customize the website navigation menu to display multi-level content links?

During the process of building and operating a website, the navigation menu plays a crucial role.It is not only a guide for users to explore the content of the website, but also the key for search engines to understand the structure of the website.AnQiCMS (AnQiCMS) fully understands this point, therefore it provides a flexible and powerful navigation menu customization feature, allowing us to easily implement the display of multi-level content links, thereby optimizing user experience and enhancing the overall efficiency of the website.Next, we will together learn how to customize and manage the website navigation menu in Anqi CMS, and make it able to flexibly display multi-level content links.##

2025-11-08

How to filter and display content under specific models or categories on the document list page?

When managing website content, we often need to display specific types or themes of content on different list pages, such as article lists, product showcase pages, or detailed summaries of custom models.This not only concerns whether users can find the information they need efficiently, but also directly affects the overall layout and user experience of the website.Anqi CMS with its flexible content model and efficient system architecture provides us with powerful tools to accurately filter and personalize content display.### The Core of Content Organization: Models and Classification In AnQi CMS

2025-11-08

How to display custom model field information in the document list?

In Anqi CMS, the flexibility of the content model is one of its outstanding advantages.Many times, we not only need to display rich content on the document detail page, but also hope to see key custom information at a glance on the document list page, such as product models, article authors, property prices, vehicle mileage, and so on.This information is often an important basis for users to quickly screen and understand the content.This article will detail how to cleverly display these custom model field information in the document list of Anqi CMS.

2025-11-08