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 for titles, keywords, or body content.AnQiCMS provides a series of practical template filters to help you easily deal with various English case conversion needs.This article will delve deep intocapfirst/lower/upperandtitleThese four commonly used filters help you achieve precise text style control in the Anqi CMS template.


lowerFilter: Full text lowercase

lowerThe filter can convert all English letters in a string to lowercase.This filter is very useful in many scenarios. For example, when you need to standardize the tags or keywords entered by users, ensuring that they are stored and displayed in lowercase to improve the accuracy of search matching,lowerIt can be put to use. It can also be used to create more informal or subdued text display effects.

The method of use is very intuitive:

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

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


upperFilter: Text uppercase

withlowerThe filter is relative,upperThe filter is responsible for converting all letters in a string to uppercase. When you want to emphasize a word, phrase, or title to make it visually more impactful,upperIt is an ideal choice. Moreover, 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 executing, you will see the output:HELLO THERE, ANQICMS!Similarly, Chinese characters will not be affected during this translation process.


capfirstFilter: Capitalize the first letter of the sentence

capfirstThe filter provides a more refined control method, it will only capitalize the first English letter of the string, while the rest of the string retains its original case.This is very suitable for formatting the beginning of a sentence, 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 habits while retaining the original essence of the content.

The followingcapfirstExample of use:

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

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


titleFilter: Title formatting (capitalize the first letter of each word)

titleThe filter is specially designed for scenarios such as titles and subtitles, it will convert the first letter of each English word in the string to uppercase, and the rest of the letters of 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, making it appear in a standard title style. Similarly, Chinese characters will not be changed by this filter.


Application suggestions and precautions

  • Combine usage:These filters can be chained together to implement more complex text processing logic. For example,{{ some_text|lower|capfirst }}Will firstsome_textconvert all to lowercase and then capitalize the first letter.
  • Chinese compatibility:Remember, all these case conversion filters are only effective for English letters, Chinese characters will remain unchanged during the conversion process.
  • Context selection:In practical applications, choose the most suitable filter based on the type of content and the purpose of display. For example, article titles may needtitleFilter, while the beginning of a common text segment is more suitablecapfirst.

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


Frequently Asked Questions (FAQ)

Ask: Do these case conversion filters have an impact on Chinese text?Answer: These filters are mainly aimed at converting English letters.When applied to a string containing Chinese characters, the Chinese character part will remain unchanged, and only the English characters will be converted to uppercase or lowercase according to the selected filter rules.

Ask: If I need to capitalize some specific letters in a string but not the first letter of each word, is there another filter that can be implemented?Answer: The one provided by AnqiCMScapfirst/lowerupperThe `title` filter is a preset of common case transformation modes.If fine control is needed (such as only capitalizing letters at specific positions rather than at word boundaries), it may be necessary to combine custom logic or process the content at the input, template filters usually do not provide this atomic character operation.

Question: Can I use multiple case filters on a variable at the same time? For example, lowercase first, then capitalize the first letter?Of course you can. Anqi CMS template filters support chained calls. For example,{{ some_variable|lower|capfirst }}Will firstsome_variableConvert all letters to lowercase and then capitalize the first letter of the entire string. Filters are separated by a pipe symbol|to connect.