The `{% contact %}` tag supports which filters to format the output content?

Calendar 👁️ 55

As an experienced website operations expert, I know that how to flexibly display and process information in a content management system is the key to improving website user experience and operational efficiency.AnQiCMS (AnQiCMS) leverages its powerful template engine and rich tag system, providing us with great convenience.{% contact %}Label, and how to output content through its filters (filters) to make your website's contact information more exquisite and practical.

Security CMS{% contact %}The flexible application of tags: how to optimize contact information display through filters

In the template design of AnQi CMS,{% contact %}The tag is the core tool used to obtain preset contact information from the background.Whether it is the company address, contact number, email, or various social media links, this tag can help us quickly retrieve it.{% contact 变量名称 with name="字段名称" %}or output directly{% contact with name="字段名称" %}.But simply retrieving information is not enough. As an operator, we often need to further format this information to adapt to different display scenarios or meet specific technical requirements.At this moment, the powerful filter of AnQi CMS comes into play.

It is worth emphasizing that,{% contact %}The tag does not directly support built-in filter parameters to change the logic of content retrieval.It focuses on accurately extracting the contact information we specify from the background database.{% contact %}The tag outputs a specific value, which (whether it is a string, number, or URL) can be treated like a regular variable and processed by subsequent general filters in a chained manner, thus achieving flexible formatting of the output content.

Next, we will combine the actual operation scenario to introduce several in the processing{% contact %}Tags are particularly practical and common filters when outputting content.

1.|safe: Ensure the safety and correct rendering of the content

In some cases, the contact information you store in the background may contain HTML code, such as an embedded WeChat QR code image tag.If you directly output this content, the template engine, for security reasons (to prevent XSS attacks), will escape it, causing the HTML code to be displayed as plain text rather than rendered correctly as images or other elements.|safeThe filter is particularly important. It tells the template engine that you confirm that this content is safe, no escaping is needed, and it can be processed directly as HTML.

Application scenario:

  • Display the WeChat QR code image uploaded on the back-end (usually one<img>tags).
  • The custom contact information field contains the HTML structure that needs to be rendered.

Example:Assuming the "WeChat QR code" field stores<img src="/path/to/qrcode.png" alt="微信二维码">.

{# 假设我们将微信二维码内容赋值给一个变量 qrcodeContent #}
{% contact qrcodeContent with name="Qrcode" %}
<div>
    <span>微信二维码:</span>
    {# 使用 |safe 确保 HTML 内容被正确解析和显示 #}
    {{ qrcodeContent | safe }}
</div>

Or, if you output directly:

<div>
    <span>微信二维码:</span>
    {% contact with name="Qrcode" %}
</div>
{# 如果 'Qrcode' 字段返回的是 URL,你可能需要这样构建图片标签 #}
<div>
    <span>微信二维码:</span>
    <img src="{% contact with name="Qrcode" %}" alt="微信二维码" />
</div>

Please note,|safeMainly used to process strings that may contain HTML. Ifname="Qrcode"Return is simply an image URL, then directly put the URL into<img>label'ssrcthe attribute, no need to|safe.

2.|defaultor|default_if_none: Gracefully handle missing information

In website operation, not all contact information will be filled in completely. If a contact information field is empty, direct output may display a blank space, affecting the page beauty or user understanding.|defaultThe filter allows you to set a default value for a variable, which will display the default text you set when the variable is empty. And|default_if_noneit is more precise to provide a default value fornil(null pointer) situations.

Application scenario:

  • When the contact phone, email, or address is not filled in, display "No information" or "Please contact customer service.".
  • Ensure that the page layout is not affected by empty values.

Example:

{% contact cellphone with name="Cellphone" %}
{% contact email with name="Email" %}

<p>联系电话:{{ cellphone | default:"暂无联系电话" }}</p>
<p>电子邮箱:{{ email | default:"请发送邮件至 [email protected]" }}</p>

{# 如果您更关注 nil 值,可以使用 default_if_none #}
<p>联系地址:{% contact address with name="Address" %}{{ address | default_if_none:"未填写" }}</p>

3.|truncatecharsor|truncatewords: Control text length.

Sometimes, the contact information entered in the background (especially for custom descriptive fields) may be quite long and not suitable for full display in some compact layouts.|truncatecharsand|truncatewordsThe filter can help you truncate text content to a specified length and add an ellipsis at the end to keep the page neat.truncatecharsTruncate by character count,truncatewordsTruncate by word count (more suitable for English content).

Application scenario:

  • Custom 'company profile' or 'contact note' field, which needs to be abbreviated for display in sidebars or footers.

Example:

{% contact customDescription with name="CompanyDescription" %}
<p>公司简介:{{ customDescription | truncatechars:50 }}</p> {# 截取前50个字符 #}

4.|upper/|lower/|title: Standardize text case

In order to maintain the consistency of the website style, you may need to display some contact information (such as social media account names, company names) in uppercase, lowercase, or with the first letter capitalized.

Application scenario:

  • To display the social media ID (such asFacebookthe username) in lowercase.
  • Capitalize the first letter of the company name.

Example:

{% contact facebook with name="Facebook" %}
{% contact companyName with name="SiteName" %}

<p>Facebook 主页:{{ facebook | lower }}</p> {# 转换为小写 #}
<p>公司名称:{{ companyName | title }}</p> {# 每个单词首字母大写 #}

5.|replaceor|cut: Clean up and format specific characters

Phone numbers often contain hyphens or spaces, if you need totel:Only keep pure numbers in URLs, or remove some interfering characters from text,|replaceand|cutThe filter will be very useful.|replaceYou can replace a substring within a string with another, and|cutit can remove all matching characters.

Application scenario:

  • from a phone number.

Related articles

If an AnQiCMS contact field is empty, how can you display default text in the template instead of leaving it blank?

## AnQiCMS template optimization: How to cleverly display default text when the contact information field is empty?In website operation, maintaining the integrity of website content and user experience is crucial.AnQiCMS (AnQiCMS) provides a solid foundation for building various websites with its flexible content management and powerful template functions.

2025-11-06

How to use `{% if %}` in AnQiCMS template to determine if a contact field exists or is not empty?

In the AnQiCMS template, we often need to decide whether to display a certain area or present information in a different way based on the presence or absence of content.This is especially critical for sensitive and important information such as contact details, we never want to leave a bunch of empty titles or broken links on the page.Today, as your website operations expert, I will take you in-depth to understand how to cleverly use the `{% if %}` tag in AnQiCMS templates to determine whether the contact information field exists or is not empty, making your website interface more intelligent and friendly.

2025-11-06

Whether the `Qrcode` image output by the contact information label supports custom `alt` text attribute?

As an experienced website operations expert, I know that every detail in a content management system can affect the overall performance of the website, whether it's user experience or search engine optimization (SEO).Today, let's delve deeper into the QR code image output of the contact information label in AnQiCMS (AnQiCMS), whether the `alt` text attribute supports customization, and how we can use it flexibly.### Security CMS QR code image `alt` text attribute customization: Insightful functions and practical strategies In modern website operations

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

How to use AnQiCMS's `{% system %}` tag and `{% contact %}` tag to combine and display the global contact information of the website?

As an experienced website operations expert, I know that effectively and uniformly managing website content is the foundation of success in an increasingly complex network environment.AnQiCMS (AnQiCMS) leverages the efficient and flexible customization capabilities of the Go language to provide us with many conveniences.Today, let's delve deeply into two seemingly simple but extremely powerful tags in Anqi CMS - `{% system %}` and `{% contact %}`, as well as how to skillfully combine them to build a unified and easy-to-maintain website global contact information display system

2025-11-06

Why did I use the `{% contact %}` tag in the AnQiCMS template but the content did not display on the front end?

As an experienced website operations expert, I know that even a small template tag problem may confuse and anxiety the operator while managing and maintaining a website.Today, let's delve into a problem that AnQiCMS (AnQi CMS) users occasionally encounter: when the `{% contact %}` tag is used in the template, no content is displayed on the front page.Don't worry, this is usually not a big problem. Just follow the steps to investigate, and we can find the cause and solve it soon.

2025-11-06

After updating the contact information on the AnQiCMS backend, why didn't the front end take effect immediately?

Hello! As an experienced website operation expert, I fully understand the confusion and anxiety you may feel when you find that the front-end does not take effect immediately after updating the AnQiCMS backend settings.This is a very common phenomenon in website operation, usually not a system failure, but a mechanism designed to improve website performance and user experience is at work.Today, let's delve into the possible reasons behind this and provide a detailed solution.### AnQiCMS Back-end contact information update, why does the front-end not take effect immediately

2025-11-06

What are the common configuration mistakes between AnQiCMS contact information settings and the `contact` tag call?

## Common Misconfigurations in Setting up AnQi CMS Contact Information: Make Your Contact Information Clear and Visible Displaying contact information clearly and effectively in website operations is a key step in building user trust, promoting communication, and transforming business. AnQiCMS provides a convenient backend setting and template tag, allowing you to easily manage and call these key information.However, even such convenient features are often hindered by seemingly minor configuration mistakes, resulting in contact information not displaying properly on the front page, causing confusion for operators

2025-11-06