In website content operation, the uniformity and aesthetics of text formatting are crucial for improving user experience.Especially when dealing with English text, flexibly controlling the case can help us better present information, whether it is used for titles, keywords, or main content.AutoCMS (AutoCMS) provides a series of practical template filters, allowing you to easily handle various English case conversion needs.capfirst/lower/upperandtitleThese four commonly used filters help you achieve precise text style control in the Anqi CMS template.


lowerFilter: Text to lowercase

lowerThe filter can convert all English letters in a string to lowercase.This filter is very practical in various scenarios.lowerIt can be put to good use. It can also be used to create more informal or subtle text display effects.

The usage method is very intuitive:

{{ "HELLO THERE, ANQICMS!"|lower }}

The output of this code will be:hello there, anqicms!. It is worth noting that if your text contains Chinese characters,lowerthe filter will only convert the English letters, and Chinese characters will remain unchanged.


upperFilter: Text converted to uppercase

WithlowerFilter relatively,upperThe filter is responsible for converting all alphabetic characters in a string to uppercase. When you want to emphasize a word, phrase, or title to make it visually more impactful,upperis an ideal choice. Additionally, it can provide convenience when dealing with abbreviations that must be strictly capitalized or creating eye-catching UI elements.

its usage is similar tolowersimilar:

{{ "hello there, anqicms!"|upper }}

After execution, you will see the output:HELLO THERE, ANQICMS!Similarly, Chinese characters will not be affected during this conversion.


capfirstFilter: Capitalize the first letter of the sentence

capfirstThe filter provides a more refined control method, which only converts the first English letter of the string to uppercase, while the rest of the string remains in its original case format.This is very useful for formatting the beginning of sentences, the first word of a list item, or any situation where only the first letter needs to be capitalized without changing the rest of the text.It ensures that the beginning of the text conforms to standard writing conventions while retaining the original essence of the content.

The followingcapfirstExample of usage:

{{ "hello there, anqicms!"|capfirst }}

This code's output result is:Hello there, anqicms!. If the string starts with Chinese characters,capfirstthe filter will not make any changes.


titleFilter: Title formatting (first letter of each word capitalized)

titleThe filter is specifically designed for scenes such as titles and subtitles, it converts the first letter of each English word in the string to uppercase, and converts the rest of the letters in each word to lowercase.This formatting method conforms to common title writing standards, making your title look more professional and standardized.

titleFilter usage example:

{{ "hello there, anqicms!"|title }}
{{ "WELCOME TO THE NEW WORLD"|title }}

Output of the first example is:Hello There, Anqicms!. Output of the second example is:Welcome To The New World。It can intelligently handle each word to present in standard title style. Similarly, Chinese characters will not be changed by this filter.


Application suggestions and precautions

  • Combined use:These filters can be chained to implement more complex text processing logic. For example,{{ some_text|lower|capfirst }}it will first convertsome_textall to lowercase and then capitalize the first letter.
  • Chinese compatibility:Please remember that all these case conversion filters are only effective for English letters, and Chinese characters will remain unchanged during the conversion process.
  • Context selection:In practical applications, choose the most suitable filter wisely according to your content type and display purpose. For example, an article title may requiretitleFilter, while the beginning of a paragraph of ordinary text is more suitablecapfirst.

Passcapfirst/lower/upperandtitleThese four filters, Anqi CMS has granted you powerful and flexible text case control capabilities in templates.Reasonably utilizing these tools can help you easily unify the format of website content, highlight key information, and ultimately enhance the overall professionalism and reading experience of the website.


Frequently Asked Questions (FAQ)

Q: Do these case conversion filters have an effect on Chinese text?答:These filters are mainly for converting English letters.When applied to a string containing Chinese characters, the Chinese character parts will remain unchanged, and only the English characters will be converted to uppercase or lowercase according to the selected filter rules.

问:If I need to convert some specific letters in a string to uppercase but not the first letter of every word, is there another filter that can be used?答:English CMS提供的capfirst/lower、Englishtitle` Filter is the preset several common case conversion modes.If you need more precise control (such as capitalizing only specific letters at certain positions instead of word boundaries), it may be necessary to combine custom logic or process it during content input, as template filters usually do not provide this atomic-level character operation.

问:我可以在一个变量上同时使用多个大小写过滤器吗?例如,先全部小写,再首字母大写?答:Of course. The template filter of Anqi CMS supports chained calls. For example,{{ some_variable|lower|capfirst }}it will first convertsome_variableConvert all the letters to lowercase, then capitalize the first letter of the entire string. Connect multiple filters with a pipe character|Connect them.