How to implement capitalizing the first letter of each word in the article title in AnQiCMS templates?

Calendar 👁️ 67

In website content operation, the standardization of article titles is often a key factor in improving the professionalism and user experience of the website.A clean and consistent title format not only makes the content more attractive but also helps improve the overall image of the website.AnqiCMS provides us with a very concise and efficient solution, where we can easily capitalize the first letter of each word in the article title with just a simple filter in the template.

Easily implement title capitalization:titleFilter

The AnqiCMS template engine borrows syntax features from Django, including various practical filters that can help us format output content. To convert the first letter of each word in the article title to uppercase and the rest to lowercase, we can usetitlefilter.

This filter is very smart, it will process each word in the title, ensuring that the first letter of each word is capitalized and the rest of the letters are converted to lowercase.This method of processing is particularly important for maintaining the consistency and aesthetics of the title, as it can automatically correct any mixed case or all uppercase words, making the title present a unified style.

How to usetitleFilter?

Firstly, we need to locate the template file that displays the article title. In AnqiCMS, the detail page of the article usually uses a template similar todetail.htmland the article list page may belist.html.

In these templates, the article title is usually output through{{ archive.Title }}or{{ item.Title }}such variables, wherearchiverepresents the article detail object,itemrepresents each item in the article list.

to apply these titles totitleFilter, just add it after the variable|titleThat's it, like this:

{# 在文章详情页中,将标题每个单词的首字母大写 #}
<h1>{{ archive.Title|title }}</h1>

{# 在文章列表页中,将列表中每篇文章的标题每个单词的首字母大写 #}
{% for item in archives %}
    <h2><a href="{{ item.Link }}">{{ item.Title|title }}</a></h2>
{% endfor %}

After you save these changes and refresh the page, you will find that all article titles are displayed neatly on your website, in the expected format, with the first letter of each word capitalized and the rest in lowercase.

Why to usetitleFilter to standardize the title?

There are several significant benefits to this unified title format:

  1. Enhance reading experience:A consistent title format makes it easier for readers to quickly browse and understand the content, reducing visual fatigue.
  2. Enhance professional image:The standardized title is an embodiment of the professionalism of the website, which can leave a better impression on visitors.
  3. Indirectly assist SEO:Although search engines are not sensitive to the case of titles, a uniform format helps improve the readability and user retention of content, which has a positive indirect impact on SEO.

AnqiCMS's template system provides a series of powerful and easy-to-use tools, such astitleThis filter function allows us to achieve fine-grained control over content display without involving complex programming, greatly enhancing the efficiency and effectiveness of content operation.

Frequently Asked Questions (FAQ)

Q1: How do I make only the first letter of the article title uppercase, not the first letter of each word?

A1: If you only need to capitalize the first letter of the entire article title, while keeping the other letters (including the first letter of subsequent words) in lowercase, you can usecapfirsta filter. For example:<h1>{{ archive.Title|capfirst }}</h1>.titleThe filter will process each word, butcapfirstThe filter only processes the first character of the entire string.

Q2: Besides the article title, I can alsotitleDoes the filter apply to other content? For example, category names or single page titles?

A2: Of course, as long as the variable you need to process is a string type and you want the first letter of each word to be capitalized (the rest in lowercase),titleFilters can be used in various situations. For example, you can use them for category titles{{ category.Title|title }}or for single-page titles{{ page.Title|title }}. This also applies to any string variables you call in the template.

Q3: If the title of the article has some words in uppercase or mixed case,titlehow will the filter handle it?

A3:titleThe filter applies by first converting the entire word (except the first letter) to lowercase, and then capitalizing the first letter of each word. This means that regardless of the original title isANQICMS cms/AnQiCMS CMSOranqicms cmsAfter|titleThe filtered content will be displayed uniformlyAnqicms CmsEnsuring high consistency in the title format.

Related articles

How to force all English text in the AnQiCMS backend custom fields to lowercase?

In website content operation, maintaining consistency in text format is a key step to improving user experience and SEO effects.Sometimes, we may encounter such a need: we hope that the English text input in the custom field of the background, regardless of how the user inputs it in uppercase or lowercase, can be forced to lowercase when displayed on the front-end.This not only makes the page look neater and professional, but also helps avoid SEO problems caused by inconsistent capitalization.

2025-11-07

How to automatically capitalize the first letter of the English name submitted by the user in the AnQiCMS template?

In website operation, we often encounter the need to display user submitted information, such as name.In order for this information to look more professional and unified, it is usually desired that the first letter of the English name be automatically capitalized.This not only enhances the beauty of the user interface, but also ensures the consistency of data display.In the flexible template system of AnQiCMS, implementing this requirement is very simple.

2025-11-07

How to remove only specific types of HTML tags in the AnQiCMS template (such as `<i>` or `<strong>`)?

In the template development of Anqi CMS, we often encounter the need to handle content output by rich text editors.This content usually includes various HTML tags, such as those used for emphasizing `<strong>`, for italicizing `<i>`, or others like `<em>`, `<span>`, `<div>` etc.

2025-11-07

How to batch remove all HTML tags from product descriptions in AnQiCMS and retain only plain text content?

In website operation, we often encounter the situation that product descriptions contain a large number of HTML tags.These tags may come from different content sources or may be accidentally introduced during the editing process, leading to poor display of the description in some scenarios, such as plain text email notifications, SEO summaries, or concise views on mobile devices.AnQi CMS provides a flexible way to solve this problem, whether it is to dynamically display plain text on the front end through templates or to perform batch processing on the back end, completely removing redundant HTML tags.

2025-11-07

How to quickly remove spaces or specific characters from both ends, left or right of a string in AnQiCMS template?

In content management, we often encounter situations where there are excessive spaces or unwanted specific characters at both ends of strings, which not only affects the display aesthetics of the content, but also sometimes causes unnecessary interference to data processing or search engine optimization (SEO).AnQiCMS uses a template engine syntax similar to Django, providing us with concise and efficient filters (Filters) to easily solve these problems.This article will introduce how to quickly remove spaces or specific characters from both ends, left, or right of a string in the AnQiCMS template.

2025-11-07

What is the correct syntax for using the `{{ obj|filter__name:param }}` filter in AnQiCMS templates?

AnQiCMS (AnQiCMS) provides strong support for content operations with its efficient and flexible features.In daily content display, we often need to process and format data in a fine-grained manner to ensure that information is presented to visitors in a **state**.At this moment, the 'filter' in the template has become an indispensable tool for us. Today, let's delve into the correct syntax for using filters in Anqi CMS templates: `{{ obj|filter_name:param }}`.Understand and master it

2025-11-07

How to set a default friendly display value for a possibly empty variable in AnQiCMS template?

When building website templates, we often encounter situations where a variable may be empty in the template due to unentered data, optional fields left blank, or specific business logic.If these empty variables are not processed, the front-end page of the website may appear blank areas, display unfriendly placeholders, and even cause layout errors, thereby affecting user experience and the professionalism of the website.

2025-11-07

How to format a 10-digit timestamp retrieved from the database into a custom date-time format in AnQiCMS template?

In website content display, we often encounter time data in a long string of numbers from the database, such as `1678886400`. This string of numbers, which is what we commonly call a timestamp, is very convenient for computers, but it seems cold and difficult to understand for users visiting websites.Fortunately, AnQi CMS provides us with a very convenient feature that can easily convert these original 10-digit timestamps into the date and time format we are accustomed to reading.

2025-11-07