In website content management, unified text format is an important factor in enhancing user experience and website professionalism.Especially for English strings, sometimes it is necessary to convert them all to uppercase to achieve emphasis, standardization, or brand display.AnQiCMS (AnQiCMS) provides a flexible "Filters" feature in template design, making this operation very simple and intuitive.

The template engine of Anqi CMS supports syntax similar to Django, and we can easily format the output strings by using specific filters, including various case transformations.

Useupper过滤器:English string in full uppercase

The most direct and commonly used method to convert all letters of an English string to uppercase isupperFilter.

The function of this filter is very clear: it will convert all English letters in the target string to uppercase, regardless of their original case. For non-English characters such as Chinese, numbers, or punctuation symbols contained in the string,upperThe filter does not perform any processing, it will remain unchanged.

Used in the templateupperThe filter is very simple, you just need to add a pipe symbol after the variable or string literal you want to convert.|,then followed byupper.

Example Usage:

If your template has a namedproductNamecontent variable, its value is"anqicms solution":

{# 原始变量输出 #}
<p>原始产品名称:{{ productName }}</p>
{# 页面输出将是:原始产品名称:anqicms solution #}

{# 使用 upper 过滤器转换为全大写 #}
<p>大写产品名称:{{ productName | upper }}</p>
{# 页面输出将是:大写产品名称:ANQICMS SOLUTION #}

even if your string is mixed case,upperThe filter can also ensure that all English characters are ultimately presented in uppercase:

{# 对混合大小写字符串使用 upper #}
<p>品牌名称:{{ "AnQiCMS Is Great" | upper }}</p>
{# 页面输出将是:品牌名称:ANQICMS IS GREAT #}

Extended applications: other case conversion filters

Exceptupper之外,SafeCMS模板还提供了其他几种实用的英文字母大小写转换过滤器,可以满足不同的显示需求,帮助您更好地控制文本的呈现方式。

  1. lowerFilter: English string in full lowercaseWithupperThe filter is opposite,lowerThe filter is used to convert all letters in an English string to lowercase.Example:

    <p>邮箱地址:{{ "[email protected]" | lower }}</p>
    {# 页面输出将是:邮箱地址:[email protected] #}
    
  2. capfirstFilter: String with first letter capitalized capfirstThe filter will convert the first English letter of the entire string to uppercase, while the rest of the string remains unchanged.Example:

    <p>问候语:{{ "hello world, how are you?" | capfirst }}</p>
    {# 页面输出将是:问候语:Hello world, how are you? #}
    
  3. titleFilter: The first letter of each word is capitalized. titleThe filter is more suitable for title-like content, which converts the first letter of each word in the string to uppercase and the rest to lowercase.Example:

    <p>文章标题:{{ "this is an amazing article about anqicms" | title }}</p>
    {# 页面输出将是:文章标题:This Is An Amazing Article About Anqicms #}
    

How to use these filters: General syntax

In the AnQi CMS template, the method of using filters is very unified and concise. You just need to add a pipe symbol after the output variable or string literal|,then follow the filter name. This syntax allows you to perform a series of data processing operations.

For example, when you have a name calledsiteTaglineThe variable, if you want to display its content in uppercase, you can write it like this:

<h1>{{ siteTagline | upper }}</h1>

This concise and powerful syntax makes text content formatting and customization highly efficient, greatly enhancing the flexibility of template development.

Summary

These case conversion filters provided by the Anqi CMS template are powerful tools for standardizing text formats and enhancing user experience in content operation. Through flexible use ofupper/lower/capfirstandtitleYou can easily create a professional and consistent website content presentation effect, ensuring that your information is conveyed to visitors in the clearest and most expected form.Master these filters, and your CMS website will have more control and appeal in content display.


Common Questions (FAQ)

Q1: Are these case conversion filters effective for Chinese or other non-English characters?A1: No, these case conversion filters (upper,lower,capfirst,title主要针对英文字符进行操作。对于中文、数字或标点符号等非英文字符,它们不会进行任何大小写转换,会保持原始字符不变。

Q2: Can I use multiple filters together? For example, convert to lowercase first and then capitalize the first letter?A2: Yes, the AnQi CMS template supports chained usage of filters. You can chain multiple filters through|Concatenated together, they are applied to the data in the order from left to right. For example, to first convert all strings to lowercase and then capitalize the first letter, you can write: {{ "HELLO world" | lower | capfirst }},其输出结果将是 “Hello world”。

Q3: If my content variable has no value (empty), will these filters cause an error?A3: Normally, when the content variable is empty, using the case conversion filter will not cause template parsing errors.They will try to handle null values, usually returning an empty string.defaultFilter to set a default value, for example:{{ someVariable | upper | default:"内容待定" }}so even ifsomeVariableis empty, the page will display “Content to be determined”.