How to use the `replace` filter to replace the old brand name with the new brand name in AnQiCMS website content?

Calendar 👁️ 76

During the operation of the website, updating the brand name is a common occurrence.Whether it is due to brand upgrading, strategic adjustment, or in order to unify the publicity口径, we need to ensure that all content on the website is synchronized with the latest brand information in a timely manner.For users using AnQiCMS (AnQi CMS), completing this task can be done either through powerful backend features or by utilizing flexible template filters.

This article will focus on how to use the AnQiCMS template inreplaceThe filter, without modifying the original database content, dynamically replaces the old brand name with the new brand name throughout the entire site.At the same time, we will briefly mention the 'Full Site Content Replacement' feature provided by the AnQiCMS backend, helping everyone choose the most suitable solution according to their actual needs.

UnderstandingreplaceThe role of the filter

In the AnQiCMS template system, a filter is a very practical tool that allows us to perform additional processing on data before it is retrieved from the database and displayed on the page.replaceThe filter, as the name implies, is used to search and replace specific strings in text content.

Its core advantage lies in:

  • Non-intrusive: replaceThe filter operates on the 'display format' of the data in the template and does not touch the original content stored in the database.This means you can always undo or modify the replacement rules without worrying about permanent data changes.This is particularly useful when testing, making temporary adjustments, or displaying different brand names according to different situations.
  • Dynamics:The replacement effect takes effect in real time. Once you apply it in the template,replacethe filter will immediately display the replaced brand name on all pages that reference the template and display the corresponding content.

replaceThe detailed usage of the filter

replaceThe basic syntax of the filter is very intuitive:

{{ 变量名|replace:"旧品牌名,新品牌名" }}

Here变量名It is the string variable you want to replace, such as article content, category name, text in system settings, etc."旧品牌名,新品牌名"It is a string containing two parts, separated by a comma,The first part is the old brand name to be replaced, and the second part is the new brand name.

Example of actual application scenarios:

Assuming your old brand name is “Old AnQi”, and the new brand name is “New AnQi”.

  1. Replace the brand name in the article or product content:This is the most common requirement. When your article content frequently mentions the old brand name, you can use a template to display the article content, usuallydetail.htmlIn a file similar to this, apply the article content variablereplacefilter.

    {# 假设 archive.Content 是文章内容的变量 #}
    <div>
        {{ archive.Content|replace:"旧AnQi,新AnQi"|safe }}
    </div>
    

    Add here|safeIt is to ensure that the HTML content is rendered correctly and not displayed as plain text.

  2. Replace the brand name in the page title, keywords, or description:The website's SEO title, keywords, and description (TDK) are crucial for search engines. You may also need to update the brand name in these locations. This is usually inbase.htmlBe completed in a specific page template.

    <title>{% tdk with name="Title" %}|{{ siteName|replace:"旧AnQi,新AnQi" }}</title>
    <meta name="keywords" content="{% tdk with name="Keywords"|replace:"旧AnQi,新AnQi" %}">
    <meta name="description" content="{% tdk with name="Description"|replace:"旧AnQi,新AnQi" %}">
    

    Please note heresiteNameIt is usually a system variable that can be applied directly.replace.tdkThe label returns the Title, Keywords, and Description; if they may also contain the old brand name, the replacement should be applied as well.

  3. Replace the custom field with brand name:If your content model or category has set custom fields and these fields contain old brand names, you can also replace these fields in the template.

    {# 假设某个自定义字段名为 custom_brand_info #}
    <p>品牌信息:{{ archive.custom_brand_info|replace:"旧AnQi,新AnQi" }}</p>
    
  4. Replace the brand name in the friend link or navigation name:Although friendship links and navigation usually have a dedicated backend management interface, but if their content is dynamically output and may contain old brand names,replacethe filter is still useful.

    {# 假设 item.Title 是友情链接或导航的名称 #}
    <a href="{{ item.Link }}">{{ item.Title|replace:"旧AnQi,新AnQi" }}</a>
    

Attention and Tips:

  • Case Sensitive: replaceThe filter is case sensitive by default. For example, if you replace"旧AnQi,新AnQi"Then, the content with "oldanqi" or "OLDANQI" will not be replaced. If you need to handle multiple cases of capitalization, you may need to call it multiple timesreplaceOr consider converting the text to uppercase or lowercase before replacing it (although the AnQiCMS filter document does not provide a filter for case conversion, some template engines may support it).
  • Global Application:The most effective method to achieve site-wide replacement is to apply in the public header file (such asbase.html)replaceFilter, or add this filter to all key output variables that will display the old brand names.
  • Delete specific words:If you want to delete an old word instead of replacing it, you can leave the new brand name part blank. For example:{{ 变量名|replace:"旧词," }}.
  • Replace with a space or other character:If you want to replace the old word with a space, you can do it like this:{{ 变量名|replace:"旧词, " }}(Note that there is a space after the comma).

When to consider using the 'Site Content Replacement' feature of the AnQiCMS backend?

AlthoughreplaceThe filter provides great flexibility at the template level, but it does not truly modify the content stored in the database. If your brand name update is permanent and you want to thoroughly clean up all the old brand names in the database, then the AnQiCMS backend provides“Full Site Content Replacement”Function would be a better choice.

You can inAnQiCMS backend -> Content Management -> Document ManagementThe page finds the entry for 'Document Keyword Replacement'. This feature allows you to directly modify the keywords or specified text in articles, products, and other content in the database. Its advantages lie in:

  • Permanent modification:Directly modify the original data in the database to ensure the consistency and accuracy of the data source.
  • Reduce template maintenance:Once the database content is updated, you do not need to add it in each templatereplacefilter.
  • More suitable for large-scale, one-time replacement:When the old brand name appears in a large amount of content and needs to be permanently updated, the background function is more efficient.

Summary

replaceThe filter is a powerful tool in the AnQiCMS template system, allowing website operators to flexibly and dynamically replace text on the page display layer without affecting the underlying data.This is very practical for testing, temporary adjustments, or displaying content according to specific rules and other scenarios.However, when the update of the brand name is permanent and involves a large amount of content, using the "All-Station Content Replacement" function in the AnQiCMS background to directly modify the original content in the database is usually a more thorough and efficient solution.Understanding the differences between these two methods and applying them flexibly according to actual needs will greatly enhance your website's operational efficiency.


Frequently Asked Questions (FAQ)

1.replaceWill the filter modify my database content?No.replaceThe filter only operates when data is retrieved from the database and prepared to be displayed on the web page.It will only affect the content that users see in the browser, and will not make any modifications to the original content stored in the AnQiCMS background database.

Related articles

The `cut` filter removes characters from a string, does it remove all matches or just the first match?

In AnQi CMS template creation, we often need to process strings, such as removing specific characters or spaces.At this point, the `cut` filter comes into play. This practical feature helps us finely adjust the content displayed on the page to ensure that the final effect meets expectations. The most common question about the `cut` filter is: When used to remove characters from a string, is it only removing the first match, or all matches?By going through the documentation and actual testing of Anqi CMS, we can clearly tell everyone

2025-11-07

How to batch remove all specific interfering characters or HTML entities from AnQiCMS article content?

It is crucial to maintain the purity and readability of content in website content operation.Whether it is content imported from outside, text processed by collection tools, or redundant characters inadvertently introduced during daily editing, these interfering factors may affect user experience and search engine optimization effects.AnQiCMS provides an efficient and powerful built-in tool to help you batch clean up various interfering characters or HTML entities from the article content, ensuring that your website content always maintains a high-quality state.### The necessity of understanding content cleaning As the accumulation of website content continues

2025-11-07

How to ensure that all unclosed HTML tags are properly closed after truncating `truncatechars_html`?

In website content operation, we often need to extract a part of the long text such as articles and product descriptions as a summary, used for list display or card preview.This can not only effectively save page space, but also attract users' attention and guide them to click to view the full content.However, when these long texts contain HTML tags, simple character truncation often leads to unclosed tags, thereby destroying the page layout and affecting the user experience.AnQiCMS (AnQiCMS) understands this pain point and has built the `truncatechars_html` filter into the template engine

2025-11-07

Can the `truncatewords_html` filter correctly handle nested HTML tags while truncating, preventing page layout chaos?

In website operations, we often need to summarize long content to attract users to click and view the details.However, directly truncating rich text content containing HTML tags often leads to page structure chaos, for example, a `<p><b>important information</p>` truncated to `<p><b>important` such a missing tag, not only ruins the visual beauty of the page, but may also lead to the entire page layout disorder.This is undoubtedly one of the most headache issues for content operators. AnQi CMS understands this pain point.

2025-11-07

What is the effect when the new word is empty in the `replace` filter while performing keyword replacement?

In AnQiCMS template language, the `replace` filter is a very practical tool that allows us to flexibly modify text content, such as replacing keywords, unifying terms, or performing simple text formatting.But a common issue when using this filter is: What if I intend to replace a word but do not provide a new replacement word?This is the core we are discussing today. ### Basic usage of `replace` filter First, let's review the basic operation of the `replace` filter

2025-11-07

How compatible are the `cut` and `replace` filters when handling Chinese character strings?

In daily website content operations, we often need to process various text content, whether it is to remove unnecessary characters or replace specific words, efficient and accurate string operations are indispensable.AnQiCMS is a modern content management system developed based on the Go language, which provides rich filters (Filters) in the template engine to meet these needs.

2025-11-07

How to quickly calculate the number of words in the AnQiCMS article summary?

In the daily operation of website content, the number of characters and words in the article introduction (or summary) is often an indispensable part of content optimization.In order to optimize for search engines (SEO), ensure that the abstract is fully displayed in the search results, or to improve the user reading experience, the length of a well-suited introduction is crucial.For those who use AnQiCMS, understanding how to effectively manage and quickly calculate the length of these summaries can significantly improve work efficiency.###

2025-11-07

The `wordcount` filter considers which delimiters in addition to spaces when distinguishing words?

In AnQi CMS template design and content management, we often use various filters to process and display data, among which the `wordcount` filter is a practical tool for counting the number of words in the text.For content operators, it is crucial to accurately understand its working mechanism, especially in distinguishing words when it considers boundaries in addition to spaces.According to AnQiCMS documentation, the `wordcount` filter's core recognition logic is **based on space separation** when calculating word count.

2025-11-07