How to get the contact information configured in the `contact` tag of AnQiCMS template?

Calendar 👁️ 61

As an experienced website operator for AnQi CMS, I am well aware of the core position of content in website construction and user interaction.Effectively and conveniently displaying contact information is an indispensable part of the website function, which directly affects the efficiency and willingness of users to communicate with the enterprise.In AnQiCMS, we provide simple and powerful template tags for this——contactAllow you to easily display the contact information configured on the backend on the website front-end.


Obtain the contact information configured in the AnQiCMS template.

AnQiCMS provides a namedcontactA template tag used specifically to retrieve and display the contact information you preset in the backend management system.The design philosophy of this label is to maximize flexibility and ease of use, ensuring that even non-technical operation personnel can easily manage and update the contact information of the website without modifying any template code.

Configuration of backend contact information

In the AnQiCMS management backend, you can navigate to the 'Contact Information Settings' area under 'Backend Settings' to configure your contact information.Here not only includes a series of default contact fields such as contact person, contact phone number, contact address, etc., but also allows you to customize additional contact parameters according to your actual needs.For example, if you want to display WhatsApp account or Facebook homepage links on your website, you can add custom fields and their corresponding values in this area.

contactBasic usage of tags

contactThe general method of using tags is{% contact 变量名称 with name="字段名称" %}.

  • 变量名称is an optional parameter, if you provide it, then the contact information value obtained will be stored in this variable, and you can refer to it in subsequent template code by{{变量名称}}. If you omit it变量名称thencontactThe label will directly output the value of the corresponding field.
  • name="字段名称"It is the key parameter of the contact information field you want to retrieve. This "field name" needs to match the parameter name in the background configuration exactly.

Let us understand how to obtain this information through some specific examples.

Get the built-in contact information field

AnQiCMS has preset a variety of common contact information fields, which can be accessed directly throughnameparameters.

  • Contact person (UserName)

    <p>联系人:{% contact with name="UserName" %}</p>
    {# 存储到变量再使用 #}
    {% contact contactPerson with name="UserName" %}
    <p>我们的联系人:{{ contactPerson }}</p>
    
  • Contact phone (Cellphone)

    <p>联系电话:{% contact with name="Cellphone" %}</p>
    <a href="tel:{% contact with name="Cellphone" %}">立即致电</a>
    
  • Contact address (Address)

    <p>公司地址:{% contact with name="Address" %}</p>
    
  • Contact email (Email)

    <p>邮箱:{% contact with name="Email" %}</p>
    <a href="mailto:{% contact with name="Email" %}">发送邮件</a>
    
  • WeChat account (Wechat)

    <p>微信:{% contact with name="Wechat" %}</p>
    
  • WeChat QR code (Qrcode)If the background is configured with a WeChat QR code image, you can obtain its URL and display it in the following way:

    <img src="{% contact with name="Qrcode" %}" alt="微信二维码" />
    
  • Social media links (for example)QQ,WhatsApp,Facebook,Twitter,Tiktok,Pinterest,Linkedin,Instagram,Youtube)AnQiCMS also has built-in common social media fields, you can call them as needed:

    <p>我们的QQ:{% contact with name="QQ" %}</p>
    <a href="https://wa.me/{% contact with name="WhatsApp" %}" target="_blank">WhatsApp联系</a>
    <a href="{% contact with name="Facebook" %}" target="_blank">访问Facebook</a>
    

Get custom contact information fields

The strength of AnQiCMS lies in its scalability.If you add a new contact field (such as a customer service hotline parameter) through the "Custom Settings Parameters" in the background contact settings, you can also retrieve its value by the parameter name in the template.

Assuming you have customized a parameter name in the backgroundServiceHotlineIts parameter value is400-123-4567.

In the template, you can call it like this

<p>客服热线:{% contact with name="ServiceHotline" %}</p>

Please note that the name of the custom parameter must match the 'Parameter Name' setting in the background when calling it in the template.

Under a multi-site environmentsiteIdParameter

For users who operate multiple AnQiCMS sites, if they need to display the contact information configured for another site in a template on a site, they can usesiteIdParameter.

For example, to get the contact phone number of a site with ID 2:

<p>子站点联系电话:{% contact with name="Cellphone" siteId="2" %}</p>

Under normal circumstances, if you only manage a single site or only need to get the contact information of the current site, you can ignore it.siteIdParameter.

Comprehensive Application Example

On the website footer or the 'Contact Us' page, you may need to display all contact information uniformly. Here is a simple example showing how to integrate multiple contact methods together:

<div class="contact-info">
    <h3>联系我们</h3>
    <ul>
        <li>
            <i class="fa fa-user"></i>
            <span>联系人:{% contact with name="UserName" %}</span>
        </li>
        <li>
            <i class="fa fa-phone"></i>
            <span>电话:<a href="tel:{% contact with name="Cellphone" %}">{% contact with name="Cellphone" %}</a></span>
        </li>
        <li>
            <i class="fa fa-envelope"></i>
            <span>邮箱:<a href="mailto:{% contact with name="Email" %}">{% contact with name="Email" %}</a></span>
        </li>
        <li>
            <i class="fa fa-map-marker"></i>
            <span>地址:{% contact with name="Address" %}</span>
        </li>
        {% contact wechatAccount with name="Wechat" %}
        {% if wechatAccount %}
        <li>
            <i class="fa fa-wechat"></i>
            <span>微信:{{ wechatAccount }}</span>
        </li>
        {% endif %}
        {% contact whatsappLink with name="WhatsApp" %}
        {% if whatsappLink %}
        <li>
            <i class="fa fa-whatsapp"></i>
            <span>WhatsApp:<a href="https://wa.me/{{ whatsappLink }}" target="_blank">{{ whatsappLink }}</a></span>
        </li>
        {% endif %}
        {# 假设您自定义了一个名为`BusinessHours`的字段 #}
        {% contact businessHours with name="BusinessHours" %}
        {% if businessHours %}
        <li>
            <i class="fa fa-clock-o"></i>
            <span>营业时间:{{ businessHours }}</span>
        </li>
        {% endif %}
    </ul>
</div>

In this way, you can create a clear and easy-to-maintain contact information display area.When the contact information changes, it only needs to be updated in the AnQiCMS background, and the front-end page will automatically synchronize the display, greatly improving the operational efficiency.


Frequently Asked Questions (FAQ)

  1. I modified the contact information on the backend, but the website front end did not update immediately, why is that?AnQiCMS to improve website performance, it usually uses a caching mechanism.After you modify the background configuration, you may need to manually clear the system cache to display the latest information on the front end.You can find the option 'Update Cache' or similar in the AnQiCMS backend to perform the operation.If clearing the cache does not update, please check if you are modifying the configuration on the correct site (if it is a multi-site environment) or if the browser cache is causing the display of old content, try clearing the browser cache or accessing in incognito mode.

  2. I added a custom contact method, but it always shows as empty when called in the template, how can I troubleshoot?First, please carefully check the template you are usingcontactlabel'snameParameter value, ensure it matches the custom parameter name you added in the backend "Contact Information Settings" exactly, including case sensitivity.AnQiCMS template tags are case-sensitive.Secondly, confirm that the custom parameter is indeed set in the background. If there are still issues, check the server logs or the AnQiCMS error logs for more detailed error information.

  3. contactCan a tag retrieve formats other than text (such as HTML)? contactThe tag is mainly used to retrieve simple data such as plain text or image URLs. If you have entered HTML content in a custom field in the background and want the front-end to parse and render these HTML, you may need to use{{变量名称}}Output when adding|safeFilter, for example{{ contactDescription|safe }}However, this needs to be done carefully to prevent potential XSS security risks. For fields like WeChat QR code images, it is usually output as is<img>label'ssrcAttribute values are used, do not need|safefilter.

Related articles

How to use the `stampToDate` tag to format timestamps in AnQiCMS templates?

As an experienced website operator deeply familiar with Anqi CMS, I know the importance of content timeliness and presentation for user experience.In website content management, the timestamp (Timestamp) is a common way to record the time of content publication and update, but displaying the timestamp directly is not intuitive for users.Therefore, formatting timestamps into readable date and time formats is a key factor in enhancing the professionalism and user-friendliness of a website.AnQiCMS provides a very convenient template tag `stampToDate`, making this operation effortless

2025-11-06

How to set the page title, keywords, description, and attach the website name using the `tdk` tag in AnQiCMS?

As a senior security CMS website operator, I am well aware of the core position of content in website construction and SEO optimization.TDK (Title, Description, Keywords) tags are an important basis for search engines to understand page content and judge the relevance of the page, as well as the information that users see first on the search results page.Efficiently setting and optimizing TDK is crucial for attracting target users and improving website rankings.Our Anqi CMS provides us with flexible and powerful TDK management functions, allowing us to finely control the metadata of each page

2025-11-06

How to use the `system` tag to obtain website name, LOGO, filing number and other system information?

As an experienced CMS website operation personnel, I fully understand the importance of dynamically obtaining basic website information in daily template development and content presentation.To ensure the consistency, ease of maintenance, and efficient management of the website, Anqi CMS provides an extremely convenient `system` tag.This tag allows template developers to directly call various system-level data from the global settings in the background, thereby avoiding the inconvenience brought by hard coding.The website's name, logo, filing number, and other information are key elements in building a brand image and legal compliance.Pass through the `system` tag

2025-11-06

How to get all Tag lists or Tags of a specified document in AnQiCMS template?

As an experienced CMS website operations personnel in the cybersecurity field, I deeply understand the importance of content tags (Tags) in website content organization, SEO optimization, and user experience.They can not only help readers quickly find the content they are interested in, but also enhance the internal links of the website and improve the efficiency of search engine crawling.In the Anqi CMS template system, the `tagList` tag is the core tool we use to achieve this goal.This article will discuss in detail how to flexibly use the `tagList` tag in Anqi CMS template to obtain all tags on the website

2025-11-06

How to implement pagination display of document list in AnQiCMS template using `pagination` tag?

As a senior Anqi CMS website operator, we fully understand that it is crucial to efficiently display a large amount of content in a content management system and ensure a user-friendly browsing experience.For a document list, pagination is the core function to achieve this goal.In the AnQiCMS template system, the `pagination` tag plays a key role in connecting the document list with page navigation, allowing a large number of documents to be presented to the user in a structured manner while maintaining flexibility and customizability.

2025-11-06

What is the difference between the `safe` and `escape` template filters in AnQiCMS and when should they be used?

As an experienced website operator for AnQiCMS, I am well aware that the correct use of templates is crucial for the safety and display effect of the website during content creation and publishing.AnQiCMS's powerful template engine provides rich features, among which the `safe` and `escape` filters play a key role in handling HTML special characters during content output.Understanding the differences and proper application is the foundation for ensuring website content security and enhancing user experience.###

2025-11-06

Which operating systems does AnQiCMS support for installation?

AnQiCMS is an enterprise-level content management system developed based on the Go language, dedicated to providing efficient, customizable, and easily scalable content management solutions for small and medium-sized enterprises, self-media operators, and those who need to manage multiple sites.Its lightweight architecture and excellent performance make AnQiCMS highly compatible in deployment and operation.As an experienced website operator, I am well aware of the importance of choosing a system with strong compatibility to ensure the stable operation of the website.Next, we will discuss AnQiCMS in detail

2025-11-06

How to manually deploy AnQiCMS on a Linux server?

As an experienced website operations manager, I am well aware of the importance of a stable and efficient content management system for the development of a company.AnQiCMS with its excellent performance in Go language and many enterprise-level features, has become an ideal choice for many small and medium-sized enterprises and content operation teams.Deploy AnQiCMS on a Linux server to fully utilize its high performance and security advantages.The following will elaborate on the steps and key points for manually deploying AnQiCMS on a Linux server, aiming to help you smoothly set up and run your content platform.###

2025-11-06