How to convert all English characters to uppercase or lowercase in the AnQiCMS template?

Calendar 👁️ 66

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

Related articles

How to safely extract from an article summary containing HTML tags without damaging the HTML structure?

In website operation, the abstract of the article plays a vital role.It is not only the first window to attract visitors to click, but also an important basis for search engines to understand page content, index, and rank.A good abstract can quickly convey the core information of the article, enhance user experience, and help with SEO performance.However, when the content of the article itself contains rich HTML tags (such as images, links, bold, paragraphs, etc.), how to safely extract a summary from these contents while avoiding destroying the HTML structure has become a common challenge.

2025-11-08

How to truncate the first N characters of an AnQiCMS article title and add an ellipsis at the end?

In website operation, we often encounter such needs: in order to make the page layout beautiful, present information succinctly, or improve search engine friendliness, it is necessary to truncate the article title and add an ellipsis at the end when the title is too long.AnQiCMS (AnQiCMS) flexible template system and rich built-in filters make this operation very simple and efficient.

2025-11-08

In AnQiCMS, what is the difference in usage scenarios between the `safe` filter and the `autoescape off` tag?

In AnQiCMS template development, we often encounter the need to display content containing HTML tags.For the security of the website, the AnQiCMS template engine defaults to automatically escaping all output variables.This means that if you directly output a text containing HTML tags such as `<strong>` or `<em>`, these tags will not be parsed as styles by the browser, but will be displayed as raw text.

2025-11-08

Why does my AnQiCMS template still escape HTML code even though I used `safe`?

When using AnQiCMS for website content creation and template customization

2025-11-08

How to remove the specified characters or extra spaces from the AnQiCMS string?

In website content operations, we often encounter situations where we need to process strings, such as cleaning up user input data, standardizing display content, or removing unnecessary characters and extra spaces from text.These seemingly minor operations can significantly improve the neatness and professionalism of website content.As an AnQiCMS user, you will find that the system provides powerful and flexible template filter functions that can easily meet these string processing needs.

2025-11-08

How to replace the old keyword with a new keyword in the AnQiCMS template?

When operating website content on AnQiCMS, we often encounter situations where we need to make minor adjustments to the website text content.Sometimes it's a change in brand words, sometimes it's the correction of typos, or adjusting the copy temporarily to cater to specific marketing activities.When these modifications need to be reflected at specific locations on the website front-end template rather than the global database, AnQiCMS provides a flexible and efficient solution.### Understand the need for keyword replacement within templates The AnQiCMS backend usually provides the "site-wide content replacement" function, which is powerful and convenient

2025-11-08

How to make AnQiCMS automatically identify URLs and email addresses in text and convert them into clickable hyperlinks?

In daily website operations, we often need to mention URLs or email addresses in the article content.If this information is just plain text, users cannot directly click to jump, and they need to manually copy and paste, which undoubtedly increases the complexity of the operation, and may also cause users to lose interest.Fortunately, AnQiCMS provides a very simple and efficient method that allows the website to automatically identify URLs and email addresses in text and convert them into clickable hyperlinks, greatly enhancing the user experience and interactivity of the website.Why automatic recognition and conversion is so important?Imagine

2025-11-08

How to automatically truncate a long URL and display an ellipsis in the middle when displaying it in AnQiCMS?

In website content operation, we often encounter the problem that long URLs cause poor page layout and affect user experience.Especially on list pages, navigation, or other display areas, if the original URL is displayed without processing, it may take up too much space and even burst the layout.In AnQiCMS, fortunately, we can elegantly solve this problem through flexible template filters, to achieve automatic truncation of long URLs and display ellipsis at the end or at a specific position.

2025-11-08