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 requirement: we hope that the English text entered in the background custom field can be forced to be displayed in lowercase on the front end, regardless of how the user enters it in terms of case.This not only makes the page look more neat and professional, but also helps avoid SEO problems caused by inconsistent case.

It is fortunate that AnQiCMS provides a very flexible content management solution, with its powerful template engine and built-in filters, we can easily achieve this goal.

Understanding the Custom Fields of AnQiCMS

AnQiCMS is positioned to serve small and medium-sized enterprises and content operation teams, it allows us to highly customize the content structure according to business needs.In the background “Content Management”->“Content Model”, we can add dedicated fields for articles, products, or other custom models.These custom fields greatly enrich the form of content expression, such as product model, brand name, product code, etc., which may contain English text.

For example, if you create a custom field named "Product Code" and set its "Field Call" toproductCode.Users may enter "ABC-123

The wonder of template engine and filters

AnQiCMS uses a syntax similar to Django template engine, which is a powerful and easy-to-use feature that allows us to handle data flexibly at the content display level.wherein, "Filters" (Filters) is the powerful tool we use for text format conversion.lowerThe filter, its function is to convert all uppercase letters in the English string to lowercase.

To force the English text of a custom field to lowercase, we do not need to modify the original data in the database, nor do we need to write complex backend code. Simply find the output location of the corresponding custom field in the template file, and apply it cleverly.lowerthe filter.

Practical Steps: Convert Custom Field Text to Lowercase

Let's go step by step to see how to implement:

  1. Determine the Call Location of the Custom FieldFirstly, we need to determine in which template file the custom field is and how it is called through a tag. Usually, custom fields are called througharchiveDetailorarchiveParamsThe label is displayed on the article or product detail page.

    • If you are directly calling a custom field (such asproductCode), it may look like this:{% archiveDetail productCode with name="productCode" %}{{ productCode }}

    • If your custom field is part of the "other parameters"archiveParamslabeled loop through the displayed, it may look like this:{% archiveParams params %}{% for item in params %}<span>{{ item.Name }}:</span><span>{{ item.Value }}</span>{% endfor %}{% endarchiveParams %}

  2. ApplylowerFilterConfirmed the call location, the next step is to add custom field values at the output location|lowerFilter.

    • For direct calls, add it after the variable|lowerHere: {{ productCode }}Change to{{ productCode|lower }}。 Complete code snippet may become:

      {% archiveDetail productCode with name="productCode" %}
      产品编码:{{ productCode|lower }}
      
    • For those who go througharchiveParamsLoop traversal scenarios, also in:item.Valuebehind|lower Will:<span>{{ item.Value }}</span>Change to<span>{{ item.Value|lower }}</span>。 Complete code snippet may become:

      {% archiveParams params %}
      {% for item in params %}
      <div>
          <span>{{ item.Name }}:</span>
          <span>{{ item.Value|lower }}</span>
      </div>
      {% endfor %}
      {% endarchiveParams %}
      
  3. Save and update cacheAfter modification, remember to save the template file.Then, a very important step is: clear the AnQiCMS system cache.At the bottom of the left menu in the background, you will find the 'Update Cache' option, click it to clear all the cache.After that, refresh your website's frontend page, and you should see that all the English text in the custom fields has been forcibly converted to lowercase.

This method only changes the display effect on the front-end, and the original data stored in the background database (including case) will not be affected. This preserves the originality of content editing while ensuring the standardization of the front-end presentation.

Some important considerations

  • Caching mechanism:AnQiCMS to improve performance, uses caching.So, after each modification of the template file, be sure to click 'Update Cache' in the background to clear the old cache data, otherwise you may not see the modified effects immediately.
  • Global and local:This transformation is for the additions you made in the template|lowerFilter