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

The AnQi CMS template engine supports syntax similar to Django, allowing us to easily format output strings using specific filters, including various case transformations.

UseupperFilter: Convert string to uppercase

The most direct and commonly used method to convert all letters of a string to uppercase is to useupperfilter.

This filter's function 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 marks in the string,upperThe filter will not perform any processing, it will remain unchanged.

Using the templateupperThe filter is very simple, you just need to add a pipe symbol after the variable or string literal you need to convert.|then followupperJust do it.

Usage example:

Suppose your template has a namedproductNamecontent variable, whose 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 eventually presented in uppercase:

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

Extended application: other case conversion filters

exceptupperOutside of this, Anqi CMS template also provides several practical case conversion filters that can meet different display requirements and help you better control the presentation of text.

  1. lowerFilter: English string in lowercasewithupperThe opposite filter,lowerThe filter is used to convert all the letters in the English string to lowercase.Example:

    <p>邮箱地址:{{ "[email protected]" | lower }}</p>
    {# 页面输出将是:邮箱地址:[email protected] #}
    
  2. capfirstFilter: Capitalize the first letter of the string capfirstThe filter will convert the first 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: Capitalize the first letter of each word titleFilters are more suitable for title-like content, they will capitalize the first letter of each word in the string and convert 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 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 process the data in a series of operations.

For example, when you have a namedsiteTaglineTHE VARIABLE, YOU WANT TO CONVERT ITS CONTENT TO UPPERCASE, CAN BE WRITTEN LIKE THIS:

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

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

Summary

These case conversion filters provided by Anqi CMS templates are powerful tools for achieving text format standardization and improving user experience in content operations. By using them flexibly,upper/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 it will enable your secure CMS website to have more control and attractiveness in content display.


Frequently Asked Questions (FAQ)

Q1: Do these case conversion filters work for Chinese or other non-English characters?A1: No, these case conversion filters (upper,lower,capfirst,titleMainly for English characters. Non-English characters such as Chinese, numbers, or punctuation symbols will not undergo any case conversion and will remain unchanged.

Q2: Can I use multiple filters together? For example, convert to lowercase first and then capitalize the first letter?A2: Yes, Anqi CMS template supports the chained use of filters. You can pass multiple filters through|Symbols are connected together, they are applied to the data in order from left to right. For example, to first convert the entire string to lowercase and then capitalize the first letter, you can write it like this: {{ "HELLO world" | lower | capfirst }}This will output 'Hello world'.

Q3: If my content variable has no value (is empty), will these filters cause an error?A3: In most cases, when the content variable is empty, using the case transformation filter will not cause the template parsing error.They will try to handle null values, usually returning an empty string.To better control the display of the page in this situation, you can combine use ofdefaultA filter can be used to set a default value, for example:{{ someVariable | upper | default:"内容待定" }}So even ifsomeVariableis empty, the page will display “Content to be determined”.