How to implement the dynamic combination output of the `add` filter in the custom `diy` tag?

Calendar 👁️ 54

In AnQi CMS, content operations strive not only for accurate information delivery, but also for the flexibility and automation of expression forms.We often encounter such needs: we hope to combine some independent content preset in the background with dynamic data on the page or fixed text in a clever way to form a complete and innovative expression.Today, let's delve deep into the AnQi CMS,addFilter and customdiyHow tags work together to help us achieve this dynamic content combination output.

diyTag: Your treasure box of content.

First, let's briefly review.diyLabel. In the Anqi CMS backend, we can flexibly create various custom fields, such as the company's customer service phone number, specific slogans, a prefix for a project, or even a brief welcome message.These fields passdiyThe label can be called very conveniently in the front-end template.It's like a treasure chest of content, storing those scattered pieces of information on the website that need to be frequently updated but don't want to be hard-coded into the template.

For example, if you set a field named "Company Name" with the value "AnQi CMS" in the "Custom Content" section of the backend, then in the template, we can easily retrieve and display it like this:

{# 在模板中获取名为“公司名称”的diy内容 #}
{% diy 公司名称 with name="公司名称" %}
欢迎来到 {{ 公司名称 }}!

This will automatically update the front-end page whenever the value of the "company name" field is modified in the background, without touching the template code.

addFilter: The magic wand for flexible content combination

simply obtain a singlediyThe content may not be enough. In actual operation, we often need to combine these independent text segments with other text or numbers to form more expressive content. At this point,addThe filter comes in handy.

addThe filter is a powerful tool built into the Anqi CMS template engine, its core function is to add or concatenate two values.This 'addition' is not limited to mathematical operations, it applies to both numbers and strings, and can even be mixed.

The basic usage is very intuitive:

{# 数字相加 #}
{{ 5|add:2 }}  {# 输出:7 #}

{# 字符串拼接 #}
{{ "安企"|add:"CMS" }} {# 输出:安企CMS #}

{# 混合类型时,字符串优先 #}
{{ "项目编号:"|add:123 }} {# 输出:项目编号:123 #}

addThis flexible feature of the filter is the key to achieving dynamic content combination output. If a value is empty,addThe filter usually ignores it intelligently, does not cause an error, and this provides additional fault tolerance for our content combination.

diywith the tag andaddThe powerful combination of filters

Now, we willdiywith the tag andaddCombine the filters and see how they spark, realizing various dynamic content combination output scenarios.

Scenario one: Dynamically build contact information or address

Suppose you are in the backgrounddiyThe "city" and "street address" fields are defined. You may want to display the complete company address at the bottom of the page.

  • diySettings:
    • name="城市",value="北京"
    • name="街道地址",value="朝阳区望京SOHO T1座"
  • Template code:
    
    {% diy 城市名称 with name="城市" %}
    {% diy 详细街道 with name="街道地址" %}
    
    <p>我们的办公地址:{{ 城市名称|add:" "|add:详细街道 }}</p>
    {# 输出:我们的办公地址:北京 朝阳区望京SOHO T1座 #}
    
    ByaddThe filter cleverly adds a space between the city and street, making the output address complete and beautiful.

Scenario two: Generate personalized action calls or slogans.

In content marketing, we often need to update the website's Call-to-Action (CTA) or slogan. If we coulddiyThe key elements defined in it, combined with fixed text, can greatly improve operational efficiency.

  • diySettings:
    • name="产品名称",value="企业建站服务"
    • name="营销前缀",value="立即体验我们的"
    • name="营销后缀",value=",助您业务腾飞!"
  • Template code:
    
    {% diy 产品服务 with name="产品名称" %}
    {% diy 前缀语 with name="营销前缀" %}
    {% diy 后缀语 with name="营销后缀" %}
    
    <a href="/contact">
        {{ 前缀语|add:产品服务|add:后缀语 }}
    </a>
    {# 输出:<a href="/contact">立即体验我们的企业建站服务,助您业务腾飞!</a> #}
    
    Just modify it in the backgrounddiyfield, the CTA on the front end will be updated accordingly, without having to modify the template.

Scene three: Combine other tags to output more information

addThe filter can not only withdiyLabel combination can also be combined with the output results of other built-in tags of the security CMS. For example, we can combine the website name in the system settings withdiyCombine content to create a dynamic website welcome message.

  • diySettings:
    • name="欢迎语前缀",value="您好,欢迎访问"
  • Template code:
    
    {% diy 欢迎前缀 with name="欢迎语前缀" %}
    {% system 网站名称 with name="SiteName" %}
    
    <h1>{{ 欢迎前缀|add:网站名称|add:"!" }}</h1>
    {# 如果SiteName是“安企CMS”,输出:<h1>您好,欢迎访问安企CMS!</h1> #}
    
    This showsaddThe powerful ability of the filter in cross-label content combination.

The practical value of content operation.

Thisdiywith the tag andaddThe pattern of combining filters brings multiple practical value to the content operation of AnQi CMS:

  1. Improve content update efficiency:The changes in marketing copy, product introduction, contact information, etc. do not require modification of the template file, just update it directly in the backgrounddiythe field.
  2. Optimize SEO performance:Flexibly combine keywords and descriptions to dynamically generate page titles, Meta Descriptions, etc., which helps search engines better understand and crawl page content, especially in scenarios where dynamic adjustment of titles based on different products or categories is required.
  3. Enhance personalization and user experience:By combining differentdiyContent, can be presented with more personalized information for different pages or user groups.
  4. Reduce operational risks:Avoid potential errors caused by directly modifying the template, decouple content management from template logic to make website maintenance safer and more convenient.

Summary

Of Security CMSdiyTags andaddThe filter may seem to be two basic functions, but when used together

Related articles

How to use the `add` filter to dynamically add navigation arrow symbols to the titles of `nextArchive` or `prevArchive`?

In website content operation, the subtle aspects of user experience often determine the overall effect.For the article detail page, if the "Previous" and "Next" navigation at the bottom of the page can be designed more intuitively, it will undoubtedly greatly improve the user's browsing efficiency and comfort level.This article will discuss how to utilize the powerful template function of Anqi CMS, especially the `add` filter, to dynamically add arrow symbols to these navigation titles, making them clear at a glance.Understand the requirement: Why to dynamically add navigation arrows?Imagine when the user has finished reading an excellent article

2025-11-07

How to dynamically add language parameters in the `add` filter of the `languages` tag that returns multilingual site links?

Under the flexible multi-language support of AnQiCMS, providing content to users worldwide has become very convenient.The system built-in `languages` tag can easily list all the language versions supported by your website and their corresponding links.However, in some scenarios, we may not only want to provide language switching functionality, but also dynamically add additional parameters to these multilingual links, such as for marketing tracking, A/B testing, or loading personalized content in specific languages.

2025-11-07

Can the `add` filter be used to concatenate CSS style strings to implement dynamic inline styles?

AnQiCMS with its flexible and powerful template engine provides great convenience to users, allowing content presentation to be highly customized according to actual needs.In daily template development, we often encounter scenarios where we need to dynamically adjust the page display based on backend data, such as changing the title color based on the article reading volume, or displaying different background styles based on user permissions.At this point, we might wonder whether the built-in `add` filter of AnQiCMS templates can be used to concatenate CSS style strings to achieve these dynamic inline style controls

2025-11-07

How to dynamically display

Display the record number at the bottom of the website, which is not only a requirement to comply with relevant laws and regulations, but also an important factor in enhancing the professionalism and user trust of the website.For users of AnQiCMS, dynamically displaying the filing number through the built-in powerful functions of the system is a very convenient operation, eliminating the need to frequently modify the code and greatly improving the maintenance efficiency of the website. ### Set the record number content in the background First, we need to set your website record number in the AnQi CMS background management interface. This is the basis of all dynamic display content, ensuring the accuracy of information

2025-11-07

How to use the `add` filter to dynamically add username and timestamp to the `commentList` comments?

AnQiCMS (AnQiCMS) with its flexible and powerful template engine, enables the presentation of website content to have a high degree of freedom.In website operation, the comment section is an important place for user interaction. Clearly displaying the information of the commenters can effectively enhance the reading experience and interaction atmosphere of the comment content.This article will introduce you in detail on how to use the `add` filter to dynamically add user nickname and timestamp to comments in `commentList`. ### Flexibly display comment data: Starting from `commentList` At

2025-11-07

Can the `add` filter directly add two numeric strings (such as "123" and "456") to get the numeric result 779?

AnQi CMS is a high-efficiency and feature-rich enterprise-level content management system, whose template engine provides flexible data processing capabilities.During template development, making good use of various filters can help us accurately control the display format of content.Today, we will delve into a common filter——`add`, especially its specific performance in handling numeric strings, which is often a place where users are likely to have doubts.

2025-11-07

How to implement multi-site content unified display and management in Anqi CMS?

In today's era where digital marketing and brand building are increasingly important, many companies or individuals often need to manage multiple websites, whether it is different brands, product lines, or multilingual, regional sites.Faced with the need for multi-site content management, AnQiCMS (AnQiCMS) provides a graceful and efficient solution that helps us easily achieve the unified display and management of content. **The Core Concept of Multi-Site Management in AnQi CMS** One of the design philosophies of AnQi CMS is that 'one system manages all'.

2025-11-07

How to utilize a flexible content model to customize the display of different types of content?

When using AnQiCMS to manage website content, we will quickly find that its 'flexible content model' feature is a core tool for content operation.It is not like traditional CMS, which confines all content to fixed 'article' or 'page' frameworks.AnQiCMS gives us the ability to define content structure, allowing us to customize the display of various types of information according to actual business needs, thereby making the website content more accurate and more attractive.

2025-11-07