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

幸运的是,AnQiCMS provides a very flexible content management solution, with its powerful template engine and built-in filters, we can easily achieve this goal.

Understand AnQiCMS custom fields

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, in the "Content Management" -> "Content Model", we can add dedicated fields for articles, products, or other custom models.These custom fields greatly enrich the expression of content, such as product models, brand names, product codes, etc., which may contain English text.

For example, if you create a custom field named "Product Code" and set its "Call Field" toproductCode. Users may enter "ABC-123", "abc-123", or "Abc-123" at the back end, but in order to display them uniformly, we hope they can all be displayed as "abc-123"。

The wonders of template engine and filters

AnQiCMS uses a syntax similar to the Django template engine, which is a powerful and easy-to-use feature that allows us to handle data flexibly at the content display level.Among them, 'Filters' is the tool we use to implement text format conversion.The AnQi CMS includes a variety of practical filters, including one namedlowerThe filter, its function is to convert all uppercase letters in a string to lowercase.

We do not need to modify the original data in the database or write complex backend code to force the English text of the custom field to lowercase. Simply find the output location of the corresponding custom field in the template file and apply it cleverlylowerthe 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 fieldFirst, we need to determine in which template file the custom field is, and through which tag it is called. Usually, custom fields are called througharchiveDetailorarchiveParamsTags are displayed on the article or product details 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" passed througharchiveParamsThe label will be cycled through and displayed, and it may look like this:{% archiveParams params %}{% for item in params %}<span>{{ item.Name }}:</span><span>{{ item.Value }}</span>{% endfor %}{% endarchiveParams %}

  2. applylowerFilterAfter determining the call location, the next step is to add it at the place where the custom field value is output.|lowerfilter.

    • For the case of direct calling, add it after the variable.|lowerJust do it: {{ productCode }}is modified to{{ productCode|lower }}The complete code snippet may become:

      {% archiveDetail productCode with name="productCode" %}
      产品编码:{{ productCode|lower }}
      
    • For those who passarchiveParamsThe same loop iteration situation applies initem.Valueadd|lower: To be<span>{{ item.Value }}</span>is modified to<span>{{ item.Value|lower }}</span>The 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, an extremely important step is: clear the system cache of AnQiCMS.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 front-end page, and you should be able to 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, the original data stored in the back-end database (including case) will not be affected, which preserves the originality of content editing while ensuring the standardization of front-end display.

Some important considerations

  • Caching mechanism:AnQiCMS to improve performance, uses caching.Therefore, after each modification of the template file, you must 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 what you added in the template:|lowerFilter