In the website built with AnQiCMS, the product details page is a key element to display core product information and attract potential customers.During template design and daily operations, we often need to flexibly adjust the text content on the page, whether for brand standards, promotional needs, or SEO optimization considerations.replaceThe 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, which can replace a specific old word with the new word we want during the rendering of the page.This brings great convenience and flexibility to content operation.
Next, let's take a look at the product details page,replaceWhat are some practical application scenarios for the filter:
Standardized content presentation: unify brand and terminology
When multiple products share the same detail template, ensuring the consistency of brand names, product feature descriptions, or industry terminology is very important.Sometimes, product data may come from different import channels or be entered by different team members, leading to various expressions in the description.For example, some product descriptions are written as "AnQiCMSreplaceUnified by the filter:
- Unified brand name:If you want to ensure that all product detail pages use a unified brand name format, for example, replacing 'AnQiCMS' in the description with 'AnQiCMS', you can use it to achieve this quickly.
- Standardized measurement units:If your product weight unit is sometimes "kg" and sometimes "kilogram", you can
replaceFilter will replace all "kg" with "kilogram" to ensure accessibility 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',
replacewe can also help you adjust it immediately.
Dynamic information update and correction: say goodbye to hard coding
The product detail page often includes contact information, price prefixes, or some general descriptions.This information may need to be frequently adjusted according to changes in marketing strategies or company policies.If this information is "hardcoded" in the product description, any 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 each product individually, just by
replaceFilter, replace '123456789' with a new contact number, or even directly call the contact number configured in the system background. - Adjust the price symbol: When your product price is just plain numbers in the backend, but the frontend needs to display a currency symbol, 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 “$” before the price with “¥”.
- Clean unnecessary text:Product data imported from the outside may sometimes contain 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-tune text for a warmer touch
Detailed content optimization can significantly improve user experience and search engine friendliness.replaceThe filter can be used to make minor but influential adjustments to the 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 fine-tune it to better match SEO strategies or user reading habits. - Link update:Some product descriptions may require link updates, or external links should be unified.
rel="nofollow"although properties.urlizeFilter can automatically handle links, but in some cases, if the link text is fixed,replaceadditional control can also be provided. - Standardize the date format:if the product details contain date text,
replaceThe filter can unify its display format, for example, replacing '2023-01-01' with '2023 January 1'.
Handle special characters and formats: make 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 a product specification may be separated by ";", but you want to display them uniformly 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 usage of the filter is very intuitive, it replaces words by specifying 'old words' and 'new words'. The basic syntax is:
{{ obj | replace:"旧词,新词" }}
Among them,objThe variable you want to operate (for examplearchive.Title/archive.Descriptionorproduct.CustomField)旧词and新词separated by English commas,.
A few simple examples:
- Replace the brand name:Suppose your product title is
安企CMS建站系统You want to display it as English:AnQiCMS建站系统:<h1>{{ archive.Title | replace:"安企CMS,AnQiCMS" }}</h1> - Unified currency symbol:If the product price is displayed as:
199$You would like to display as:¥199:<p>价格:{{ archive.Price | replace:"$,¥" }}</p> - Remove specific text (leave the new word blank):If the product description inadvertently includes text such as “(This is a test content)” and you want to remove it:
Note: When<div class="product-description">{{ archive.Description | replace:"(此为测试内容), " | safe }}</div>objWhen the content contains HTML, in order for the replaced HTML code to be correctly parsed by the browser, be sure toreplaceafter the filter|safeFilter.
By using flexibilityreplaceFilter, you can achieve greater freedom in content management on the product detail page of the AnQiCMS.It makes the fine-tuning of frontend content simple and efficient, without the need to delve into complex code changes, nor the need to frequently update the background data, thereby greatly enhancing the operation efficiency and professionalism of the website.
Common Questions (FAQ)
1.replaceWhat is the difference between the 'Whole Site Content Replacement' function of the filter and AnQiCMS backend?
replaceFilters are used during template rendering to process specific variables (such as{{ archive.Description }})Performing text replacement.Front-endOperation, it does not change the original content stored in the database. While the "Full Site Content Replacement" feature directly modifiesDatabaseThe content is, a backend batch processing function, changes are permanent. Simply put, the filter is 'instant display adjustment', and the background function is 'data source modification'.
**2.