How to automatically capitalize the first letter of an article title, or to achieve full uppercase/lowercase conversion?

Calendar 👁️ 77

In content operation, a standardized and unified title format is crucial for the brand image of the website and the user reading experience.In order to enhance the visual neatness or meet specific design styles, automatically adjusting the case of article titles is a very practical feature.AnQiCMS as a flexible content management system, provides a convenient way to help us achieve this goal without complex programming, making it easy to handle.

AnQiCMS's template engine is powerful and easy to use, it comes with a variety of filters (Filter), which are like small tools that can process and format data.The automatic conversion of article titles to uppercase, full uppercase, or full lowercase is exactly done through these filters.

Capitalize the first letter of the title automatically (Capfirst)

If you want the first letter of the article title to be automatically capitalized while the rest of the letters remain unchanged (for example, “hello world” becomes “Hello world”),capfirstThe filter is your ideal choice. It can make the title look more formal and standardized in many cases.

How to use:Suppose you pass through it in the template.{{ item.Title }}To display the article title, just in.TitleAdd after|capfirstthe filter.

Code example:

{# 假设 item.Title 的原始值为 "anqicms 让内容管理更简单" #}
<div>文章标题:{{ item.Title|capfirst }}</div>
{# 输出效果: 文章标题:Anqicms 让内容管理更简单 #}

{# 或者获取单篇文章详情时的标题 #}
{% archiveDetail articleTitle with name="Title" %}
<div>文章标题:{{ articleTitle|capfirst }}</div>
{# 输出效果(假设原始标题为 "安企cms:网站运营新选择"):文章标题:安企cms:网站运营新选择 #}
{# 注意:capfirst 仅对英文字母有效,中文字符不会被转换。#}

Capitalize the title (Uppercase)

Sometimes, to emphasize a title or meet specific design requirements, you may need to convert all the letters of the article title to uppercase (for example, “hello world” becomes “HELLO WORLD”). At this point, you can useupperfilter.

How to use:Likewise, in displaying the article title's{{ item.Title }}Add after|upperfilter.

Code example:

{# 假设 item.Title 的原始值为 "anqicms is awesome" #}
<div>文章标题:{{ item.Title|upper }}</div>
{# 输出效果: 文章标题:ANQICMS IS AWESOME #}

Lowercase the title in full

The opposite of all uppercase, if your website design style is more relaxed, informal, or has other special requirements, you may want to convert all article titles to lowercase (for example, "Hello World" becomes "hello world").lowerThe filter can help you achieve this.

How to use:In{{ item.Title }}Add after|lowerthe filter.

Code example:

{# 假设 item.Title 的原始值为 "AnQiCMS CONTENT MANAGEMENT SYSTEM" #}
<div>文章标题:{{ item.Title|lower }}</div>
{# 输出效果: 文章标题:anqicms content management system #}

Additional hint: Capitalize the first letter of each word in the title (Title case)

Except for the few common conversions mentioned above, AnQiCMS also provides atitleA filter that can capitalize the first letter of each word in a title and convert the rest to lowercase (for example, “hello world” becomes “Hello World”).This is a very standard title format, commonly used for book chapters, news headlines, etc.

How to use:In{{ item.Title }}Add after|titlefilter.

Code example:

{# 假设 item.Title 的原始值为 "how to use anqicms filters" #}
<div>文章标题:{{ item.Title|title }}</div>
{# 输出效果: 文章标题:How To Use Anqicms Filters #}

Apply these formatting in the AnQiCMS template

These filters need to be modified in your website template file. Typically, the article title will bearchiveDetailtags (used to display the details of a single article) orarchiveListTags (used to call the article list) are called.

  1. Locate the template file:The template files of AnQiCMS are usually located in the root directory of the system under./templateThe folder and named with.htmlThe end. You need to find the corresponding file responsible for displaying the article title according to the actual template structure of the website (for examplearchive/detail.htmlfor the article detail page,archive/list.htmlor the homepageindex/index.htmlfor the article list).
  2. Find the title output position:Find similar in these template files:{{ archive.Title }}or{{ item.Title }}This is where the article title is output.
  3. Add a filter:InTitleAdd the corresponding filter after the variable, such as{{ item.Title|capfirst }}.

It is noteworthy that these filters only change the display effect of the title on the front-end page, they will not modify the original article title data stored in the database.This means you can flexibly use different formatting methods on different pages or locations without worrying about data consistency issues.

By flexibly using these built-in filters, you can easily achieve the standardization and beautification of article titles, thereby enhancing the overall professionalism and user experience of the website.Choose the formatting style that best suits your website's style and content needs, making your content more outstanding.


Frequently Asked Questions (FAQ)

Ask: Does this title formatting affect the SEO effect of the article?Answer: Generally speaking, capitalizing article titles in the template layer will not have a negative impact on SEO. Search engines primarily focus on the page<title>The text of the title (H1, H2, etc.) in the label and content.If the content of these tags is accurate and relevant, search engines can usually understand and index them correctly.These filters only change the display style and do not change the semantic content of the title.

Ask: If I want to format the article titles of specific categories or models, how should I operate?Answer: You can use conditional judgment in the template (iftag) combined withcategoryIdormoduleIdTo implement. For example, inarchiveListorarchiveDetailAfter getting the article data through the tag, proceed toif item.CategoryId == 10orif item.ModuleId == 2Such conditions are used to determine whether to apply a specific filter. This can customize the title display format for different content types.

Ask: Besides the title, where can these filters be applied?Answer: These string processing filters can be applied to any text type variable.For example, you can apply them to article descriptions (Description), category names (Category Title), tag names (Tag Title), or any custom text field.Any text output in the template can be converted to uppercase or lowercase as needed to achieve a unified display style.

Related articles

How to correctly escape special characters in the AnQiCMS template to avoid display errors?

In website content management, we often need to display text containing various special characters.If these special characters are not handled correctly, it may lead to page layout chaos, functional anomalies, and even security vulnerabilities.AnQiCMS provides a powerful mechanism to help us handle these special characters during template rendering, ensuring the correct display of content and the security of the website.

2025-11-08

How to safely concatenate string and numeric variables in the AnQiCMS template?

During the development of AnQiCMS templates, we often need to combine different text segments, numerical information, and even system variables to form a complete output content, such as building dynamic links, displaying formatted data, or generating user-friendly prompt information.This process involves concatenating strings and numeric variables, and how to safely and efficiently complete this operation is an indispensable aspect of template development.AnQiCMS's powerful template engine provides a variety of flexible mechanisms to support these needs.AnQiCMS template engine syntax is similar to Django

2025-11-08

How to randomly get a character or value from a string or array?

In Anqi CMS template design, we often encounter the need to dynamically display content, such as randomly recommended articles, randomly displayed product images, or randomly selecting one from a set of preset keywords for display.To achieve this flexible and varied content presentation, Anqi CMS provides simple and powerful template filters, including the `random` filter that can randomly select a character or value from a string or array.Understand and master the `random` filter, which can make our website content more vibrant and fresh, effectively enhancing the user experience

2025-11-08

How to configure multi-site content display in AnQiCMS

Easily implement multi-site content management and display in AnQiCMS It is a challenge for users who operate multiple brands, sub-sites, or content branches to manage the content of each site uniformly.AnQiCMS provides powerful multi-site management features, allowing you to easily create and maintain multiple independent websites under a single system instance and flexibly control the display of their content.This article will give a detailed introduction on how to configure multiple sites in AnQiCMS and achieve independent management and display of content.### 1. Prepare the work

2025-11-08

How to achieve text centering or left-right alignment formatting in templates for AnQiCMS?

In web design, the layout and alignment of content are key elements of user experience.No matter if you want to center the title or align the paragraph text to the left, AnQiCMS provides a flexible template mechanism, combined with standard Web technology, which can easily meet these needs.AnQiCMS as a content management system developed based on the Go language has its core advantages in providing efficient, customizable content management and data output.It uses a syntax similar to the Django template engine, allowing you to combine system data (such as article titles, content, etc.) with

2025-11-08

How to determine if a string or array in the AnQiCMS template contains a specific keyword?

In Anqi CMS template development and daily content operation, we often encounter the need to dynamically display information based on specific attributes or keywords of the content.To achieve personalized content recommendation, emphasize the specific theme of an article, or control the display of page elements based on certain indicators in the data, accurately determining whether a string or array contains specific keywords is a very practical skill.The Anqi CMS template system adopts a syntax similar to the Django template engine, built-in with rich filters and tags, which can help us easily implement such judgments. Next

2025-11-08

How to count the number of times a certain keyword appears in the article content in the AnQiCMS template?

In content operation, understanding the frequency of keywords in articles is an important part of SEO optimization and content strategy analysis.By counting the frequency of keywords, we can better evaluate the density, relevance, and even discover potential optimization spaces.AnQiCMS provides a powerful and flexible template system,配合 its built-in content filter, we can easily count the number of occurrences of specific keywords in the article content.### Understanding the need: Why do we need to count keywords?Count the number of times a keyword appears in an article, mainly including the following practical application scenarios: 1.

2025-11-08

How to remove specific characters or extra spaces from AnQiCMS template variables?

In website content operations, we often encounter such situations: the template variable content retrieved from the database may contain some unnecessary characters, extra spaces, or formats that are not satisfactory.These subtle details, if not handled properly, may affect the aesthetics of the page, user experience, and even cause interference with search engine optimization (SEO).AnQiCMS provides powerful template filtering functionality, helping us easily clean and format these variables.The template syntax of AnQiCMS is similar to Django engine

2025-11-08