On an AnQiCMS-built website, the product detail page is a key element for displaying core product information and attracting potential customers.During template design and daily operation, we often need to flexibly adjust the text content on the page, whether for brand standards, promotional needs, or SEO optimization considerations.This is provided by AnQiCMS at this timereplaceThe filter can be put to good use, helping us to replace and optimize content on the front-end page without modifying the back-end data source.
ThisreplaceThe filter acts like an intelligent text processor that can replace a specific old word with the new one we want during the rendering of the page.This brings great convenience and flexibility to content operations.
Let's take a look at the product details page together,replaceWhat are the practical application scenarios of the filter:
Standardize content presentation: unify brand and terminology
When multiple products share a detail template, it is very important to ensure the consistency of brand names, product feature descriptions, or industry terminology.Sometimes, product data may come from different import channels or be entered by different team members, leading to various descriptions.For example, some product descriptions are written as "AnQiCMS", and some as "AnQiCMS".In order to maintain the consistency of the page style, we can usereplaceUnified by the filter:
- Unified brand name:If you want to ensure that all product detail pages use a uniform brand name format, such as replacing 'AnQiCMS' in the description, you can use it to quickly achieve this.
- Standardized units of measurement:Suppose the weight unit of your product is sometimes "kg" and sometimes "kilogram", you can use
replaceThe filter will uniformly replace all “kg” with “kilogram”, ensuring barrier-free reading for users. - Adjust the tone of the product description:If a product description contains the word 'cheap', and you would rather express it as 'economical'
replaceit can also help you adjust immediately
Dynamic information update and correction: goodbye to hard coding
Product detail pages often include contact information, price prefixes, or some general descriptions.This information may need to be adjusted frequently according to changes in marketing strategies or company policies.If this information is 'hardcoded' in the product description, each modification requires editing a large amount of product content.replaceThe filter makes these changes easy.
- Update contact information:If your product description often mentions a fixed customer service phone number “123456789”, but now this phone number needs to be changed. You do not need to edit the products one by one, just by going through the template.
replaceFilter, replace '123456789' with a new contact phone number, and can even directly call the system backend configured contact phone number. - Adjust the price symbol:When your product price may just be a pure number in the background, but the frontend needs to display currency symbols, you can replace the null value in the price field with a specific currency symbol, or replace one currency symbol with another.For example, replace the dollar sign '$' before the price with '¥'.
- Clean unnecessary text:Product data imported from external sources sometimes contains some fixed text or watermark information that comes with the product but is not needed to be displayed on your website. You can use
replaceThe filter clears it.
Optimize user experience and SEO: fine-tuning text is more considerate
Detailed content optimization can significantly improve user experience and search engine friendliness.replaceThe filter can be used to make small but influential adjustments to page content.
- Keyword optimization:If you find that a keyword appears too frequently in the product description or the wording is not natural enough, you can use
replacethe filter to adjust it to better fit SEO strategies or user reading habits. - Link update:Some product descriptions may need to update the links, or add external links uniformly.
rel="nofollow"Although.urlizeThe filter can automatically handle links, but in certain cases, if the link text is fixed,replaceit can also provide additional control. - Unified date format:if the product details contain date text, through
replaceThe filter can unify its display format, for example, replacing '2023-01-01' with '2023 January 1'.
Handle special characters and formatting: make the data cleaner.
When displaying product parameters, feature lists, or importing content from non-standard data sources, it is often encountered that the format is not unified or contains special characters.
- Standard separator: For example, multiple parameters of product specifications may be separated by “;”, but you want to display them as “、” on the front end
replaceThe filter can easily achieve this conversion, making the layout more beautiful. - Remove specific characters:If the product name or description accidentally contains special characters that are not allowed to be displayed (such as HTML tags or other symbols),
replaceIt can help you clear them, ensuring the content is pure.
How to usereplaceFilter
replaceThe use of the filter is very intuitive, it replaces the "old word" with the "new word". The basic syntax is:
{{ obj | replace:"旧词,新词" }}
Among them,objis the variable you want to operate (for examplearchive.Title/archive.DescriptionOrproduct.CustomField)旧词and新词separated by English commas,Separated.
Here are some simple examples:
- Replace brand names:Suppose your product title is
安企CMS建站系统Would you like to unify the display ofAnQiCMS建站系统:<h1>{{ archive.Title | replace:"安企CMS,AnQiCMS" }}</h1> - Unified currency symbol:If the product price is displayed as
199$Then you would like to display as¥199:<p>价格:{{ archive.Price | replace:"$,¥" }}</p> - Remove specific text (leave the 'new word' blank):If the product description accidentally includes text like "(This is for testing)" and you want to remove it:
Note: When<div class="product-description">{{ archive.Description | replace:"(此为测试内容), " | safe }}</div>objWhen containing HTML content, be sure toreplaceafter the filter|safefilter.
By flexible applicationreplaceFilter, you can get more freedom in content management on the AnQiCMS product detail page.It makes frontend content fine-tuning simple and efficient, without the need to delve into complex code changes, nor frequent updates to backend data, thereby greatly improving the operation efficiency and professionalism of the website.
Frequently Asked Questions (FAQ)
1.replaceWhat is the difference between the filter and the 'Full Site Content Replacement' feature of AnQiCMS backend?
replaceFilters are used during template rendering, for specific variables like{{ archive.Description }})Performing text replacement ofFront-endoperation does not change the original content stored in the database. The backend "Full Site Content Replacement" function directly modifiesDatabaseThe content is a backend batch processing feature, changes are permanent. In simple terms, the filter is 'instant display adjustment', and the background feature is 'source data modification'.
**2.