In daily website content operations, we often need to standardize the management of user input or system-generated content, especially when it involves brand names.Maintaining brand name consistency and accuracy is crucial not only for enhancing brand image but also for the SEO performance of the website, legal compliance, and user experience.AnQi CMS provides a flexible and powerful template engine, among whichcontainA filter is a very practical tool that can help us efficiently check if the text contains preset brand names.
Why do we need to check brand names in the content?
Under the scenario of website content operation, checking the frequency and accuracy of the brand name appearance has multiple meanings:
- Brand consistencyEnsure that all published content uses the correct, unified brand name spelling (for example, always use "AnQiCMS" instead of "AnQi CMS" or "anqicms"), which is crucial for building a professional brand image.
- SEO optimization: Search engines pay attention to the consistency of keywords when understanding and indexing web content.Brand name as a core keyword, its unified use helps to improve the search engine ranking of related pages.
- Compliance and risk controlSome industries or specific situations may require avoiding the mention of competitors' brand names or ensuring the lawful use of one's own brand name.By means of the inspection mechanism, it can effectively avoid potential legal risks.
- Content QualityThe use of standardized brand names is a sign of high-quality content, avoiding reading obstacles or misunderstandings caused by casual spelling.
containThe wonder of filters
The Anqi CMS template engine provides a rich set of filters,containIt is one of them. Its core function is to judge whether a string, array, key-value pair, or structure contains the specified "keyword" and returns a boolean value (TrueorFalseThis makes it an ideal choice for checking if a brand name exists in the text.
Review of basic usage:
{{obj|contain:关键词}}
here,objis the content you want to check (for example, the text entered by the user), and关键词Then it is the brand name you want to search for.
How to utilizecontainThe filter checks if the text entered by the user contains the preset brand name?
Assuming we have a content publishing system, users can enter text in the article content or product description.We hope to check if these texts contain our company's own brand name 'AnQi CMS'.
Step 1: Get the text to be checked.
This usually comes from the article content field, custom fields, or form data submitted by users.In AnQi CMS templates, these data are usually obtained through tags or variables.For example, on the detail page of an article, you can access the content of the article:
{% archiveDetail articleContent with name="Content" %}
{# articleContent 现在包含了文章的完整内容 #}
Or, if it is a custom form field, such as the product name filled in by the user in the commentproduct_name:
{# 假设有一个变量 input_text 存储了用户输入 #}
{% set user_input_text = guestbook_form.product_name.Value %}
Second step: usecontainFilter to check
Now, we can compare the obtained text content with the preset brand name.
Example 1: Check a single brand name
Assuming the brand name we preset is "AnQi CMS". We can check it like this in the template:
{% set user_input_text = articleContent %} {# 或者其他你想要检查的文本变量 #}
{% set hasAnqiCMS = user_input_text|contain:"安企CMS" %}
{% if hasAnqiCMS %}
<p style="color: green;">内容中包含品牌名称“安企CMS”,符合规范。</p>
{% else %}
<p style="color: red;">注意:内容中未检测到品牌名称“安企CMS”。请确保品牌名称正确。</p>
{% endif %}
In this example,hasAnqiCMSThe variable will be based onuser_input_textwhether it contains "AnQi CMS".TrueorFalse. Then, we can display different prompts based on this boolean value.
Example 2: Check multiple brand names (or variants)
In actual operation, the brand name may have multiple spellings or related keywords that need to be checked simultaneously.For example, in addition to "AnQiCMS", it may also be necessary to check "AnQiCMS" or "AnQi Content Management System".
due tocontainThe filter checks one keyword at a time, we can combine multiple check conditions using logicorOr iterate through a list of brand names:
Method A: Use logicorCombine conditions
{% set user_input_text = articleContent %}
{% set hasAnyBrandName = user_input_text|contain:"安企CMS" or user_input_text|contain:"AnQiCMS" or user_input_text|contain:"安企内容管理系统" %}
{% if hasAnyBrandName %}
<p style="color: green;">内容中包含预设的品牌名称或其变体。</p>
{% else %}
<p style="color: red;">注意:内容中未检测到任何预设的品牌名称或其变体。</p>
{% endif %}
This method is suitable when there are not many brand names to check.
Method B: Traverse the list of brand names (more flexible)
If the brand name list is long, or needs to be loaded dynamically from the configuration, we can first define a brand name array and then iterate to check. AlthoughcontainThe filter itself does not directly receive an array as keywords, but combined with loops andsettags can be implemented:
{% set brand_names_to_check = ["安企CMS", "AnQiCMS", "安企内容管理系统"] %}
{% set user_input_text = articleContent %}
{% set found_brand = false %}
{% for brand_name in brand_names_to_check %}
{% if user_input_text|contain:brand_name %}
{% set found_brand = true %}
{% break %} {# 找到一个即可停止循环 #}
{% endif %}
{% endfor %}
{% if found_brand %}
<p style="color: green;">内容中包含预设的品牌名称或其变体。</p>
{% else %}
<p style="color: red;">注意:内容中未检测到任何预设的品牌名称或其变体。</p>
{% endif %}
This method is more scalable and convenient for managing a large list of brand names.
Practice and **recommendations
- Application scenario:Except for the content of the article,
containThe filter can be applied to comment review, user messages, custom form submissions, automatic checking of website titles or descriptions, and other scenarios. - Feedback mechanism: After finding or not finding the brand name, clear feedback can be provided.In the background, this may mean adding a tag to the content;On the front end, reminders or guides to correct the user can be displayed.
- Combine with other features:
containFilters are usually combined with other control flow tags (such asif/set/for) to build more complex logic. - Handle case sensitivity carefully: Please note, the security of the Anqi CMS.
containThe filter isCase sensitiveThis means that 'AnqiCMS' and 'Anqi cms' are considered different keywords.If you need to perform a case-insensitive check, you can consider converting the text to be checked and the keywords to the same case (e.g., all to lowercase) before the check, but this requires the corresponding Safe CMS template engine to provide it.lowerorupperThe filter is supported. According to the document,lowerandupperThe filter is supported, so it can be implemented like this:{% set user_input_text_lower = user_input_text|lower %} {% set brand_name_lower = "安企CMS"|lower %} {% set hasAnqiCMS_case_insensitive = user_input_text_lower|contain:brand_name_lower %} - Avoid over-matching:
containThe filter checks for substrings. For example, checking 'Apple' might match 'Pineapple'.In some cases, this may not be the result you want. If you need more precise word matching, you may need to combine more complex logic or regular expressions (if the Anqi CMS template engine supports it) to achieve this.
By flexible applicationcontainThe filter can greatly improve the automation and standardization of website content management, ensure the consistency of the brand image, and optimize the user experience during content consumption.
Frequently Asked Questions (FAQ)
Q1:containIs the filter case-sensitive?A1: Yes,containThe filter is case sensitive. For example, checking if “AnQi CMS” contains “cms” will returnFalseIf you need to perform a case-insensitive check, it is recommended that you convert the text to be checked and the target keywords to the same case before using the filterlowerorupperFilter to convert to uniform case and then proceedcontainCheck.
Q2: How to check if the user's input text contains any of the predefined brand names?A2: You can use logicorCombine multiplecontainCheck conditions, for exampleuser_input_text|contain:"BrandA" or user_input_text|contain:"BrandB". If the list of brand names is long, a more flexible approach is to first store all the brand names in an array variable, then throughforLoop through this array and execute for each brand namecontainCheck and stop the loop once a match is found
Q3: Besides strings,containCan the filter check other types of data?A3: Yes, according to the Anqi CMS documentation,containFilters can be used for strings and can also judge a keyword.