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”.
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, usually
detail.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.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 in
base.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 here
siteNameIt 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.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>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 as
base.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 template
replacefilter. - 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.