In website content display and management, maintaining uniformity of text format is a key factor in enhancing user experience and maintaining brand image.Especially the case of English characters, sometimes it is necessary to unify the specification according to design or business requirements.AnQiCMS as an efficient and flexible content management system, fully considers these needs, and provides us with a quick and convenient method for English character case conversion through its powerful template functions.

The working principle of AnQiCMS template engine

AnQiCMS's template system uses syntax similar to the Django template engine, which brings us great convenience and flexibility.In AnQiCMS template, we use 'filters' to process and format the output variables.|Connect behind the variable, for immediate processing of the variable's content.For example, to convert a variable to uppercase, we just need to add the corresponding case conversion filter after the variable.

The core filter for implementing English character case conversion

The AnQiCMS template includes a special filter to meet the needs of English character case conversion. The most commonly used and direct tool isupperandlowerfilter.

  1. Convert to uppercase:upperFilter

    upperThe filter can convert all letters in a string to uppercase.When you need to emphasize a word, display product models uniformly, or the overall style of the website needs to be in uppercase, this filter is particularly useful.

    Usage method: In the template, you just need to adduppera filter to the variable that needs to be converted, like this:

    {{ 你的变量 | upper }}
    

    Actual example: Suppose you have a product title variable{{ product.Title }}Its value is"anqicms template tutorial". When you applyupperAfter the filter, that is{{ product.Title | upper }}will be displayed on the page"ANQICMS TEMPLATE TUTORIAL".

    Code snippet demonstration: On the product list page, if you want all product names to be displayed in uppercase, you can write the template code like this:

    {% archiveList products with type="list" moduleId="2" limit="5" %}
        {% for item in products %}
            <li><a href="{{ item.Link }}">{{ item.Title | upper }}</a></li>
        {% endfor %}
    {% endarchiveList %}
    

    This code will iterate through all products and ensure that their titles are displayed in uppercase format on the page.

  2. Convert to lowercase:lowerFilter

    withupperCorresponding to the filter,lowerThe filter converts all letters in the English string to lowercase. This is very useful for maintaining a unified and concise style of text, or in places where it is not desired to be too prominent.

    Usage methodSimilarly, you just need tolowerapply the filter to the variable that needs to be converted to lowercase:

    {{ 你的变量 | lower }}
    

    Actual exampleIf{{ article.Description }}the value of the variable is"AnQiCMS Is A Powerful And Flexible CMS."then{{ article.Description | lower }}will output"anqicms is a powerful and flexible cms.".

    Code snippet demonstrationWhen displaying the introduction of an article, you may wish to use lowercase letters to maintain the continuity of the content:

    {% archiveDetail articleContent with name="Description" %}
        <p>{{ articleContent | lower }}</p>
    {% endarchiveDetail %}
    

    In this way, all English characters in the article summary will be presented in lowercase, making the visual appearance softer and more unified.

More flexible case control:capfirstandtitleFilter

In addition to converting to uppercase or lowercase completely, AnQiCMS also provides more refined case control filters, which are also very useful in specific scenarios and can be used as a supplement toupperandlower: the supplement

  • capfirstFilterThis filter will only capitalize the first letter of a string, while the rest of the string remains unchanged.

    • For example:"hello world" | capfirstwill output"Hello world"It is suitable for scenarios where the first letter of a sentence needs to be capitalized.
  • titleFilter:titleThe filter will capitalize the first letter of each word in the string.

    • For example:"hello world" | titlewill output"Hello World"This is very convenient for standard title formatting.

AlthoughcapfirstandtitleThe filter provides additional flexibility, but if your goal is to convert all English characters to uppercase or lowercase, thenupperandlowerit is still your preferred tool.

Application scenarios and precautions

  • Uniform content formatNo matter if it's a product name, brand name, user review, or any other place where a unified English character case is required, these filters can provide strong support.They can help you maintain consistency in content style when displaying on the front end, even if the original data's case format is not uniform.
  • Does not affect non-English characters: Please rest assured,upper/lower/capfirstandtitleThese filters are mainly aimed at converting English characters. For Chinese, numbers, or special symbols, etc., non-English characters will remain unchanged, and no side effects will occur.
  • Process HTML ContentIf your variable contains HTML tags (for example, the article content is obtained from a rich text editor), and you want to convert the case of the English characters inside the HTML tags while keeping the HTML structure, it is usually sufficient to apply a filter. For example,{{ item.Content | upper }}Will<p>hello world</p>changes to<p>HELLO WORLD</p>. If you want to remove HTML tags first and then convert case, you can use the chained callstriptagsa filter such as{{ item.Content | striptags | lower | safe }}.
  • chaining call: AnQiCMS template supports chaining of filters, you can pass multiple filters through the pipe character|Connect them together, they will process the variables in order from left to right, which provides great flexibility.

Summary

AnQiCMS through its intuitive and easy-to-use template engine and rich built-in filters, makes the formatting of website content effortless. Whether it is to convert all English characters to uppercase to highlight, or to lowercase to keep it simple,upperandlowerFilters can provide powerful and flexible support to help you easily manage and display high-quality website content, making your website also show professionalism in every detail.

Frequently Asked Questions (FAQ)

  1. Q: Do these case filters affect Chinese or other non-English characters?A: No.upper/lower/capfirstandtitleThese filters mainly act on English characters.They recognize English letters and perform case conversion when processing strings, but they will keep non-English characters such as Chinese, numbers, or special symbols unchanged, without any change.

  2. Q: Can I use multiple filters on the same variable? For example, convert it to lowercase first and then capitalize the first letter?A: Yes, AnQiCMS template supports chained filter calls. You can connect multiple filters using the pipe character|Connect multiple filters together