When managing website content in AnQi CMS, we often need to make the category page more than just a simple aggregation of document lists, but also to carry more exclusive information to better guide users or showcase the characteristics of the category.At this point, it is particularly important to add and obtain custom fields for categorization.By these custom fields, you can make each category page unique, whether it's displaying specific Banner images, contact information, or the unique properties of the category.

Understanding the importance of category custom fields

AnQi CMS provides powerful content models and classification management features, allowing us to define various custom fields for content (such as articles, products) to meet different business needs.Similarly, the category itself supports adding these personalized custom information.This means, in addition to the basic attributes such as category name, description, etc., you can also set custom fields such as "Category Banner Large Image", "Unique contact information for this category", and "Featured tag description" in the background according to your needs.

These fields, once set, are like a unique 'brand' on the category, greatly enriching the expressiveness of the category page.For example, if you operate a travel website, you can add a dropdown field for "**Travel Season" under the "Island Trip" category, or set a numeric field for "Recommended Age Group" under the "Family Trip" category.Thus, when users visit these category pages, they can get more accurate and practical information at a glance.

Get custom fields on the category details page

We need to use the built-in Anqicms on the category detail page template to display these custom fieldscategoryDetailThe tag is the key to obtaining detailed category information. It can not only help us obtain the basic data such as category ID, title, link, and description, but also access the custom fields defined for the category in the background through a special parameter.

After you add custom fields for categories in the background (usually edit a category in "Category Management", and set them in the "Other Parameters" or "More Model Custom Fields" section), these fields will be encapsulated by an enterprise CMS namedExtrain the data set.

To retrieve and iterate over all custom fields, you can go to the category details page template (usually){分类模型}/list.htmlor the custom template file you have specified for the category, and use it in this way.categoryDetailTags:

{% categoryDetail categoryExtraFields with name="Extra" %}
{% if categoryExtraFields %}
    <div class="category-custom-info">
        <h3>分类附加信息</h3>
        {% for field in categoryExtraFields %}
            {# 仅显示有值的自定义字段 #}
            {% if field.Value %}
                <p><strong>{{ field.Name }}:</strong> {{ field.Value|safe }}</p>
            {% endif %}
        {% endfor %}
    </div>
{% endif %}

In this code block:

  • {% categoryDetail categoryExtraFields with name="Extra" %}We have defined a variablecategoryExtraFieldsto store all the custom fields of the current category.name="Extra"It indicates that we want to retrieve these additional custom data.
  • {% if categoryExtraFields %}This is a simple judgment to ensure that the content below is rendered only when the category exists with custom fields, avoiding unnecessary empty modules on the page.
  • {% for field in categoryExtraFields %}: Due toExtraIt returns an array or list containing multiple custom fields, we need to useforloop to iterate through them.
  • {{ field.Name }}: It will output the parameter name you set for the custom field in the background (for example, "**Travel Season").
  • {{ field.Value|safe }}:It will output the specific value of this custom field (for example, “spring and autumn”)。Here|safeThe filter is very important, especially when your custom field content may contain HTML rich text, it ensures that the content is parsed and displayed correctly, rather than as plain text output.

If you know the "call field name" of the custom field (i.e., the lowercase English field name used when defined in the background, such asbestSeason), you can also directly go throughcategoryDetailTo retrieve the value of this specific field without traversing all fields:

{% categoryDetail with name="bestSeason" %}

This allows you to directly locate and display the content of a specific custom field in the template, which is very convenient when you only need to display specific information instead of listing all custom fields.

Practical Tips

  1. Back-end settings are fundamental:All custom fields must be created first in the Anqi CMS backend under 'Content Management' -> 'Document Categories', select the category you want to edit, and enter the editing interface.In the "Other parameters" or "More model custom fields" area, add and configure these fields according to your needs.Please note that the "parameter name" is for the backend administrator to see, while the "calling field" is the name you use to directly retrieve a specific field in the template.
  2. Flexible use of field types:The Anqi CMS supports various custom field types, such as single-line text, multi-line text, numbers, single choice, multiple choice, and drop-down selection.Choose the appropriate type based on the actual use of your custom field, as this affects its input form in the background and the presentation of values on the front end.
  3. Conditional judgments are indispensable:When displaying custom fields in templates, it is recommended to add conditional judgments (such as{% if field.Value %}Avoid blank labels or unattractive prompts on the page when a field is not filled in.
  4. Note|safeUsage:If your custom field content may contain HTML tags (for example, if you are using a rich text editor), please be sure to use|safeThe filter, otherwise the HTML code will be escaped and displayed as plain text.

By these flexible custom field and template calling methods, Anqi CMS makes your category detail page more dynamic and information-rich, thus better serving your website operation goals.


Frequently Asked Questions (FAQ)

1. Why am I trying to get custom fields on the category detail page, but there is no content displayed on the page?First, please check if you have indeed added custom fields in the 'Document Category' editing page of the Anqi CMS backend, and that these fields have actual values. Second, confirm that you are using the correctcategoryDetaillabels, especiallyname="Extra"parameters, and looped throughcategoryExtraFieldsvariables. If you directly access a specific field, make surenameThe value of the parameter matches the calling field name you have defined in the background and is spelled correctly in uppercase and lowercase.

**2. I can directly access a specific custom field instead of iterating over all