In AnQi CMS template development, in order to better control the display format of content, the system provides a variety of text processing filters. Among them,capfirst/lower/upperandtitleAre several commonly used filters for adjusting the case of English strings.They each have unique purposes and scope, understanding the differences can help us beautify and standardize web page text more accurately.
Let's discuss their functions one by one and find out the similarities and differences between them.
lowerFilter: Full lowercase
lowerThe filter's function is intuitive and simple: it converts all letters in the target string to lowercase. Whether the original string is uppercase, lowercase, or mixed case, afterlowerAfter the filter, all letters will be presented in lowercase.This filter is often used in scenarios where uniform text formatting is needed, case-insensitive comparison, or generating SEO-friendly lowercase URLs.
For example, if you have a variabletext = "AnQiCMS 是一个内容管理系统"After{{ text|lower }}After processing, the output will be"anqicms 是一个内容管理系统"It should be noted that non-English characters (such as Chinese, numbers, or special symbols) will not be affected by this filter.
upperFilter: All uppercase
withlowerThe opposite filter,upperThe filter will convert all English letters in the target string to uppercase. When you need to emphasize a word, create an all-uppercase title, or unify text in a specific design style,upperThe filter will be very useful.
Similarly to the above.text = "AnQiCMS 是一个内容管理系统"For example, after.{{ text|upper }}After processing, the output will be"ANQICMS 是一个内容管理系统". AndlowerLike the filter, it only affects letters.
capfirstFilter: Capitalize the first letter.
capfirstThe filter is the most "precise" among these four in terms of scope. It will only take the first English letter of the string.The first English letterConvert to uppercase, while other characters in the string (including subsequent English letters) will remain unchanged.This filter is usually used at the beginning of a sentence, in item descriptions, or any situation where only the first letter of the first word needs to be capitalized.
If your variablesentence = "hello anqicms world!"after{{ sentence|capfirst }}Processed, the output will be"Hello anqicms world!"Please note that only the first letter of a string that can be capitalized will be capitalized, even if there are other words starting after it.
titleFilter: Capitalize the first letter of each word
titleThe filter is more suitable for formatting title-like text. It will capitalize the first letter of each word in the stringThe first letter of each wordConvert to uppercase and then convert the rest of each word to lowercase.This means it not only capitalizes the first letter of each word but also unifies possibly mixed-case words into a standard title format.
When we processtitle_text = "this is an anqicms title"Use{{ title_text|title }}The result is"This Is An Anqicms Title"It ensures that each word starts with an uppercase letter and the rest is lowercase, which is very practical for standardizing website titles, article titles, or product names.
Summary and comparison
| Filter name | Object in action | Conversion effect | Example input | Example output (English characters part) |
|---|---|---|---|---|
lower |
English letters in the entire string | Convert all letters to lowercase | AnQiCMS TEXT |
anqicms text |
upper |
English letters in the entire string | Convert all letters to uppercase | AnQiCMS text |
ANQICMS TEXT |
capfirst |
The first letter of the string | Only the first letter is capitalized, the rest is not | hello AnQiCMS world |
Hello AnQiCMS world |
title |
Letters of each word | Capitalize the first letter of each word, the rest are lowercase | this IS an ANQICMS title |
This Is An Anqicms Title |
It is not difficult to see from the above comparison that these four filters provide different precision controls for string case handling.lowerandupperIs a global conversion, whilecapfirstandtitleIt focuses more on the formatting of text structure (sentences or words).In practical applications, choose the appropriate filter according to the specific text display effect you want to achieve to make your content more professional and unified.
Frequently Asked Questions (FAQ)
Do these case conversion filters have an effect on Chinese or other non-English characters?Answer: These filters (
capfirst/lower/upper/titleMainly designed for processing English strings.When applied to a string containing Chinese, numbers, or special symbols, it will only convert the English letters contained within, and other non-English characters will remain unchanged.I have an English sentence, and I want to achieve the effect that the first letter of each sentence is uppercase and the other letters are lowercase. Which filter should I use or how should I combine them?Answer: If you need to convert the entire sentence into a standard sentence form (the first letter of the sentence capitalized and the rest of the words in lowercase), you can first use
lowerThe filter converts all letters to lowercase and then usescapfirstThe filter capitalizes the first letter of a sentence. For example:{{ "THIS IS A TEST SENTENCE."|lower|capfirst }}It will output"This is a test sentence.".Where should I use these filters in the AnQiCMS template?Answer: These filters can be used anywhere text variables need to be output.For example, in positions where article titles, category names, tag texts, and custom field content need to be displayed on the page.
|Apply the filter chain to the variable after that.They are very useful for unifying page style, improving text readability, and even assisting in SEO optimization in some scenarios (such as ensuring the case consistency of URLs or titles).