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