`trimLeft` and `trimRight` filters are used to remove which parts of the string in AnQiCMS templates??

Calendar 👁️ 73

In Anqi CMS template development, we often need to control and adjust the content displayed on the page in detail.The filter is a set of powerful tools provided by the Anqi CMS template engine that help us easily change the output format and content of variables.Today, we will focus ontrimLeftandtrimRightThese very practical filters play a key role in handling extra content at the beginning and end of strings. To better understand them, we will also briefly mention their 'brother' filterstrim.

UnderstandingtrimFilter: Clean both ends of the string

Further understandtrimLeftandtrimRightBefore that, let's take a look at first.trimfilter.trimThe function is to remove the suffix of the string.All leading and trailing spaces or specific characters.

If you just use it simply.{{ 你的变量|trim }}It automatically removes all extra spaces, tabs, and newline characters from the beginning and end of the string. This is very convenient for standardizing input data or removing unexpected blank spaces caused by layout.

When you want to remove specific characters, you can pass these characters as parameters totrimFor example,{{ "欢迎使用安企CMS"|trim:'欢迎CMS' }}. It should be noted that it checks if the parameters are present at both ends ofany characterRemove it and continue until a character not in the set is encountered. For example, in the above example, it removes the '欢' and '迎' at the beginning, as well as the 'C', 'M', and 'S' at the end, resulting in使用安企.

trimLeft:Precisely delete the left part of the string

As the name implies,trimLeftThe filter focuses on processing the string'sleft (i.e., the beginning)part. Its behavior is similar totrimbut its scope of action is limited to the beginning of the string.

If you have a string欢迎使用安企CMS(Note that there are spaces at the beginning and end), use{{ " 欢迎使用安企CMS "|trimLeft }}, and the result will be欢迎使用安企CMS. As you can see, the spaces on the right side of the string are still preserved."),

Similarly, you can specify the character set to be removed. For example,{{ "欢迎使用安企CMS"|trimLeft:"欢迎" }}Remove '欢' and '迎' characters from the beginning of the string (if they exist), get使用安企CMS. This filter is very useful when we need to remove a fixed prefix or clean up unnecessary leading characters from user input, for example, when processing CSV data, it may be necessary to clear the specific delimiter at the beginning of the line.

trimRight: Precisely delete the right part of the string

trimRightThe filter works the opposite, it focuses on removing the string'sright side (i.e., the end)part. It will remove all the extra spaces at the end of the string or the specific characters you specify.

For example,{{ " 欢迎使用安企CMS "|trimRight }}The result is欢迎使用安企CMS. The leading spaces in the string are preserved.

If you want to remove specific characters at the end of the string, like{{ "欢迎使用安企CMS(AnQiCMS) "|trimRight:") " }}It will remove all ')' and spaces at the end, resulting in `Welcome to AnQiCMS(AnQiCMS)

Related articles

How to remove extra spaces or specific characters from the beginning and end of a string in AnQiCMS template?

In AnQiCMS template development, fine-grained string processing is a key factor in improving the quality of website content display.We often encounter such a situation: when data is read from the database, user submissions, or text imported from external sources, the beginning or end may carry spaces that we do not want, or even specific punctuation marks or prefix/suffix characters.These extra characters not only affect the visual cleanliness of the page, but may also cause unnecessary trouble to front-end layout, data validation, and even search engine optimization (SEO).AnQiCMS uses similar

2025-11-08

In the AnQi CMS content settings, how does the 'Automatically filter external links' feature affect the published content?

In Anqi CMS content settings, there is a feature called 'Whether to automatically filter external links', which has a direct and profound impact on the publication of website content.This seemingly simple switch actually affects many aspects such as the website's search engine optimization (SEO), user experience, and the credibility of the content. To find this feature, you need to enter the Anqi CMS backend management interface, and you can see it under the "Content Settings" menu in the "Backend Settings".It provides two main options, each leading to different processing results after content is published.###

2025-11-08

How to use the `replace` filter to replace the old word with a new word in the template?

When managing website content on AnQi CMS, we often encounter situations where we need to fine-tune the text displayed in the template.Maybe the brand name needs to be updated, a certain keyword needs to be unified, or it is just to correct a small display error.At this time, if we always go to modify the source content, it may seem inefficient.

2025-11-08

What replacement rules does the "Document Keyword Replacement" feature support in the AnQiCMS backend?

In the daily operation of websites, we often need to adjust keywords in a large number of articles or product descriptions to adapt to the latest SEO strategies, brand specification updates, or changes in content marketing direction.Manually modifying one by one is not only time-consuming and labor-intensive, but also prone to errors.AnQiCMS (AnQiCMS) deeply understands the pain points of content operators, especially in the backend, where it has designed a powerful "document keyword replacement" function to help users manage and optimize website content more intelligently and efficiently.What rules does the 'Document Keyword Replacement' feature of Anqi CMS support?

2025-11-08

How does AnQiCMS's Markdown editor handle special characters and formatting?

AnQiCMS provides a powerful Markdown editor that not only simplifies content creation but also allows for flexible handling of special characters and formats to meet the needs of different content displays.For users, understanding these processing methods can better utilize the editor's potential to output high-quality page content. ### Enable Markdown Editor Firstly, to use the Markdown editor, you need to make simple settings in the Anqi CMS backend.

2025-11-08

How to safely output HTML code in the AnQiCMS template to prevent escaping?

In website operation, we often encounter situations where we need to output content containing HTML code.For example, images, links in the main text, or custom style layouts, etc.When you output this content in an AnQiCMS template, you may find that it is not displayed as interactive elements as expected, but rather displayed in the original HTML code form, for example, `<p>This is a paragraph</p>` becomes `&lt;p&gt;This is a paragraph&lt;/p&gt;`.

2025-11-08

What special characters are the `escape` and `escapejs` filters used to escape in the AnQiCMS template?

In AnQiCMS template development, to ensure the correct display of content and website security, we often use some built-in filters to handle special characters.Among them, the `escape` and `escapejs` filters are two very important tools, each serving different scenarios, and the types of special characters that need to be escaped are also different.

2025-11-08

How can keyword library management in AnQiCMS's SEO tool help optimize website content?

In the increasingly fierce online competition, optimizing website content is the key to attracting and retaining users.For operators who want to stand out in search engines and continuously obtain high-quality traffic, a set of efficient SEO tools is undoubtedly a powerful assistant.AnQiCMS as an enterprise-level content management system provides many practical functions in SEO, among which keyword library management is the core tool for us to optimize website content and improve search engine performance. Imagine your website as a library, and keywords are like indexes guiding readers to the books you provide.

2025-11-08