In Anqi CMS, content operations strive not only for accurate information delivery but also for flexibility and automation in expression forms.We often encounter such needs: we hope to cleverly combine some independent content preset on the backend with dynamic data on the page or fixed text, forming a complete and innovative expression.addFilter and CustomdiyHow tags work together to help us achieve this dynamic content combination output.

diyTags: 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, prefixes for a project, or even short welcome messages.diy

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

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

This way, no matter how the backend modifies the value of the 'Company Name' field, the front-end page will automatically update without touching the template code.

addFilter: The magic wand for flexible content combination

Just to get a singlediyThe content may not be sufficient yet. In actual operation, we often need to combine these independent text fragments with other text or numbers to form more expressive content. At this time,addThe filter comes in handy.

addThe filter is a powerful tool built into the Anqi CMS template engine, whose core function is to 'add' or 'concatenate' two values.This 'addition' is not limited to mathematical operations, it is applicable 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 implementing dynamic content combination output. If a value is empty,addThe filter will usually intelligently ignore it, without causing errors, which provides additional fault tolerance for our content combination.

diyTags andaddThe strong combination of filters

Now, we willdiyTags andaddCombine filters and see how they ignite sparks, achieving various dynamic content combination output scenarios.

Scenario one: Dynamically construct contact information or address.

Suppose you are in the background.diy【en】It defines two fields: "City" and "Street Address". You might want to display the full company address at the bottom of the page.

  • diy【en】Settings:

    • name="城市",value="北京"
    • name="街道地址",value="朝阳区望京SOHO T1座"
  • 【en】Template Code:

    {% diy 城市名称 with name="城市" %}
    {% diy 详细街道 with name="街道地址" %}
    
    
    <p>我们的办公地址:{{ 城市名称|add:" "|add:详细街道 }}</p>
    {# 输出:我们的办公地址:北京 朝阳区望京SOHO T1座 #}
    

    PassaddThe filter cleverly adds a space between cities and streets, making the output address complete and aesthetically pleasing.

Scene two: Generate personalized call to action or slogans.

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

  • diy【en】Settings:

    • name="产品名称",value="企业建站服务"
    • name="营销前缀",value="立即体验我们的"
    • name="营销后缀",value=",助您业务腾飞!"
  • 【en】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 frontend CTA will be updated accordingly without modifying the template.

Scene three: Output more detailed information by combining other tags

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

  • diy【en】Settings:

    • name="欢迎语前缀",value="您好,欢迎访问"
  • 【en】Template Code:

    {% diy 欢迎前缀 with name="欢迎语前缀" %}
    {% system 网站名称 with name="SiteName" %}
    
    
    <h1>{{ 欢迎前缀|add:网站名称|add:"!" }}</h1>
    {# 如果SiteName是“安企CMS”,输出:<h1>您好,欢迎访问安企CMS!</h1> #}
    

    This demonstratesaddThe powerful capability of filters in content combination across tabs.

The practical value of content operation

ThisdiyTags andaddThe pattern of combining filters brings multiple practical values to the content operation of Safe CMS:

  1. Enhance content update efficiency:The changes in marketing copy, product introduction, contact information, etc. do not require modifying the template file, update directly in the backenddiyfield.
  2. Optimize SEO performance:Combine keywords and descriptions flexibly to dynamically generate page titles, Meta Descriptions, etc., which helps search engines better understand and capture page content, especially in scenarios where titles need to be dynamically adjusted according to different products or categories.
  3. Enhance personalization and user experience:By combining differentdiycontent, it can present more personalized information for different pages or user groups.
  4. Reduce operational risks:Avoid potential errors caused by directly modifying templates, decouple content management from template logic, making website maintenance safer and more convenient.

Summary

Anqi CMS'sdiyTags andaddThe filter, although it seems to be two basic functions, becomes