How to implement the conversion of the first letter to uppercase or all uppercase of the string in AnQiCMS template?

Calendar 👁️ 64

In website content presentation, the case format of strings often needs to be flexibly adjusted according to different scenarios, such as the first letter of the article title in uppercase, the full lowercase of the username, or the full uppercase of the brand name, etc.AnQiCMS as a rich-featured enterprise-level content management system, its template engine provides convenient and powerful filters (Filters), which help us easily achieve the case conversion of these strings, making the content display more standardized and professional.

The case conversion function of AnQiCMS template

AnQiCMS's template system adopts a syntax similar to the Django template engine, one of its core advantages is that it provides a rich set of "filters".These filters can perform various processing and formatting operations on variables in the template, including the string case conversion that we will discuss in detail today.

The basic syntax of using filters in AnQiCMS templates is very intuitive:{{ 你的变量 | 过滤器名称 }}If the filter requires additional parameters, the format is{{ 你的变量 | 过滤器名称:参数 }}In this way, we can directly control the display style of content at the template level without modifying the backend code.

Next, we will understand the four commonly used string case conversion filters and their applications in the AnQiCMS template.

Implement the uppercase conversion of the first letter of the string (capfirst)

When you need to capitalize the first letter of a string while keeping the rest unchanged,capfirstA filter is an ideal choice. It is often used at the beginning of sentences, for capitalizing the first letter of specific names or brand names, and other scenarios.

Usage:Just pass the variable to be processed through the pipe symbol.|Connected tocapfirstthe filter.

{{ 你的变量 | capfirst }}

Example:Assume your variablepageTitleThe value is"anqicms 是一款优秀的内容管理系统"ApplycapfirstAfter the filter:

{{ pageTitle | capfirst }}

Output Result: Anqicms 是一款优秀的内容管理系统

It is worth noting that,capfirstThe filter mainly processes the first letter of English strings. For Chinese characters, it usually does not produce case conversion effects.

Implement title case conversion (capitalize the first letter of each word)title)

For titles, names, places, or any text that needs to follow title case rules,titleThe filter can capitalize the first letter of each word in a string and convert the rest to lowercase. This is very helpful for maintaining the unity and professionalism of the website content.

Usage:

{{ 你的变量 | title }}

Example:Assume your variablearticleHeaderThe value is"anqicms 模板使用指南"ApplytitleAfter the filter:

{{ articleHeader | title }}

Output Result: Anqicms 模板使用指南

withcapfirstsimilar,titleThe filter also mainly targets English strings. It intelligently identifies word boundaries (such as spaces) and capitalizes the first letter of each word.

Perform full uppercase conversion (upper)

Sometimes, to emphasize a word, show an abbreviation, or maintain a specific brand style, you need to convert all the letters of the entire string to uppercase.upperThe filter can easily meet this requirement.

Usage:

{{ 你的变量 | upper }}

Example:Assume your variableproductCodeThe value is"aq-cms-v3"ApplyupperAfter the filter:

{{ productCode | upper }}

Output Result: AQ-CMS-V3

Implement full lowercase conversion (lower)

withupperThe opposite filter,lowerThe filter is used to convert all letters in a string to lowercase.This is very useful when it is necessary to standardize user input (such as email addresses), generate uniform tags, or URL aliases.

Usage:

{{ 你的变量 | lower }}

Example:Assume your variableuserNameThe value is"Administrator"ApplylowerAfter the filter:

{{ userName | lower }}

Output Result: administrator

Practical application and precautions

This case-insensitive string converter filter can be applied to any string variable obtained from the AnQiCMS backend, including article titles (archive.Title), category names (category.Title) of Page Description (page.Description) of System Settings (system.SiteName) or any custom field.

A few points to note when using these filters:

  • Language LimitationThe above all case conversion filters are mainly for English strings.For Chinese characters or other non-English characters, they usually do not produce uppercase or lowercase conversion effects, or the effects may not be as expected.
  • Non-string valueIf the filter is applied to a non-string variable (such as a number), it will usually be output as is without an error, but it will not be converted either.
  • chaining call: AnQiCMS template filters support chained calls, which means you can combine multiple filters for use, for example{{ yourString | lower | capfirst }}.

By flexibly using these built-in string case conversion filters, AnQiCMS users can better control the presentation of website content, thereby enhancing user experience and the overall professionalism of the website.


Frequently Asked Questions (FAQ)

Q1: Do these case conversion filters work for Chinese string?

A1:No, in the AnQiCMS template,capfirst/title/upperandlowerFilters are mainly designed for English string design. They cannot perform case conversion for Chinese characters. For example, using "安企CMS"}upperFilter, the output will still be 'Anqi CMS'.

Q2: Besides article titles and content, what other variables can I use these filters on?

A2:You can use these filters for any string type template variables. This includes but is not limited to:

  • Article/product related variables: such asarchive.Title(Title),archive.Description(Description),archive.Keywords(Keywords), or custom model fields.
  • Categorization related variables: such ascategory.Title(Category Name),category.Description(Category description).
  • Single page related variables: such aspage.Title(Page title),page.Description(Page description).
  • System/Contact Information Settings: such assystem.SiteName(Website Name),contact.UserName(Contact), or any custom setting parameters.

Q3: If I need to determine if a string contains a substring, does the AnQiCMS template have a corresponding filter?

A3:Yes,

Related articles

How to format a floating-point number to a specified number of decimal places in AnQiCMS template?

In the presentation of website content, we often need to display various numbers, such as product prices, discount percentages, or statistical data.These numbers are often floating-point numbers, and in order to ensure the beauty of the page layout and the clarity of the information, we usually need to format them, such as uniformly retaining two decimal places.In the AnQiCMS template, thanks to its flexible template engine, we can conveniently use the built-in `floatformat` filter to meet this requirement.

2025-11-07

How to automatically convert a URL string into a clickable hyperlink and set `nofollow` in the template of AnQiCMS?

In the daily operation of AnQi CMS, we often need to display external links in the website content.These links, if they are just simple text, not only affect the user experience, but also cannot effectively convey information.At the same time, in order to follow the **practice** of search engine optimization (SEO), especially for links pointing to external sites, we usually want to add the `rel="nofollow"` attribute to avoid unnecessary "weight loss" or passing unnecessary trust.AnQi CMS provides a simple and efficient method to solve this problem.### Core Function Revelation

2025-11-07

How to calculate the number of elements in a string (such as an article title) or an array (such as a tag list) in AnQiCMS templates?

In AnQi CMS template design, we often need to make accurate statistics of the content on the page, whether it is to dynamically display the number of data or to make conditional judgments based on the number, mastering how to calculate the number of elements in a string or array is particularly important.AnQiCMS's powerful template engine provides a concise and efficient method to handle these requirements.

2025-11-07

How to convert newline characters in multi-line text to the HTML `<br>` tag for display in AnQiCMS templates?

In AnQiCMS content management, we often enter multi-line text with line breaks, such as article content, product descriptions, or contact addresses.However, when this content is displayed on the website front-end, we may find that the original clear line breaks are missing, and all the text is squeezed into a single line.This not only affects the reading experience of the content, but may also be inconsistent with our original design intention.Why is this happening?

2025-11-07

How to customize the display content and link of the homepage Banner in AnQiCMS template?

In website operation, the homepage banner acts as the 'facade' of the website, and its visual effect and guiding role are crucial.A well-designed and tasteful Banner can not only attract visitors' attention but also effectively convey the core information of the website and guide users to take the next step.For friends using AnQiCMS, how to flexibly customize the display content and link of the home page Banner is a key step to improve the user experience and marketing effect of the website.

2025-11-07

How to loop to display user group information in AnQiCMS template?

In the website built with AnQiCMS, the user grouping function provides us with powerful content management and user permission division capabilities, whether it is to implement membership content, display different information according to user level, or plan VIP services, user grouping is an indispensable foundation.How to flexibly display these user grouping information on the front-end template of a website, which is a focus for many operators.AnQiCMS uses a template engine syntax similar to Django, which makes template writing intuitive and efficient.When it comes to user group information, the system provides

2025-11-07

How to get and display detailed information of a specific user, such as username, avatar, and level in AnQiCMS template?

In website operation, displaying personalized information to users, such as usernames, avatars, and membership levels, can greatly enhance user experience and website interaction.AnQiCMS as a flexible content management system provides intuitive template tags to help us easily achieve this goal.The AnQiCMS template system has adopted a syntax similar to Django templates, allowing backend data to be called through concise tags.When we want to display detailed information about a specific user

2025-11-07

How to display or hide content blocks in AnQiCMS templates based on conditions (such as `if` statements)?

In website content operation, we often need to display or hide specific content based on different situations, such as displaying special event information on holidays or showing different operation buttons based on the user's status.AnQiCMS provides a flexible template engine, allowing you to easily implement these dynamic content controls, with the most core tool being the conditional statement - `if`. AnQiCMS template syntax is similar to the popular Django template engine, and it is very easy to get started with.

2025-11-07