How to retrieve custom fields of a category on the category detail page?

Calendar 👁️ 64

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

Related articles

How to implement multi-level category nesting display in Anqi CMS?

The organization of website content is crucial for user experience and information retrieval efficiency.A clear and logical classification system can help visitors quickly find the information they need, and also lay a good foundation for the website's SEO.In Anqi CMS, implementing nested display of multi-level categories is the key to building this efficient content architecture.It is not just to list categories simply, but also to modularize and organize the content through hierarchical relationships, whether it is product display, article archive, or service introduction, it can be presented to users in a more intuitive way.

2025-11-08

How to get all category lists under a specified model in AnQi CMS?

AnQi CMS with its flexible content model design makes content management efficient and elastic.Whether it is an enterprise official website, a marketing website, or a personal blog, there may be a need to display the corresponding category list according to different content models (such as articles, products, or custom models).Understanding how to accurately retrieve these categories in the template is a key step in fully utilizing the powerful functions of AnQi CMS.In AnQi CMS, the content model is the foundation of organizing content.

2025-11-08

How to get and display category thumbnails or Banner carousel?

The attractiveness of visual content is crucial in website operation.A well-designed category thumbnail and an eye-catching banner carousel not only beautifies the website interface but also effectively guides users to browse, enhancing the overall professionalism and user experience of the website.AnQiCMS (AnQiCMS) offers powerful and flexible features that allow you to easily manage and display these important visual elements.This article will provide a detailed introduction on how to obtain and display category thumbnails or Banner carousel in Anqi CMS.

2025-11-08

How to display the name, description, content, and link of the category?

When building a website, category information is not only the skeleton of the content, but also the key to user navigation, search engine optimization (SEO), and improving user experience.AnQiCMS (AnQiCMS) with its flexible template engine allows you to easily display categories, descriptions, content, and links on the website frontend, providing visitors with a clear navigation path and rich information for search engines to better understand your website structure.This article will delve into how to flexibly call and display your website's category information through several core tags in the AnQiCMS template.

2025-11-08

How to display the complete content and all fields of a single page?

In Anqi CMS, a single page is the basis for building static content pages such as 'About Us' and 'Contact Information'.Effectively displaying the complete content of these pages and all their fields is crucial for website customization and user experience.The Anqi CMS provides intuitive and powerful template tags, allowing you to easily display single-page data configured in the background on the website front-end. To display the complete content of a single page and all related fields, we mainly use the `pageDetail` core template tag.

2025-11-08

How to retrieve and display all single page lists in AnQi CMS?

Managing and displaying single pages in Anqi CMS is one of the basic functions for website content construction.A single page is usually used to create pages with relatively fixed structures and independent content, such as 'About Us', 'Contact Information', or 'Service Introduction', etc.If you wish to display a list of single pages in a specific area of the website, such as the footer navigation or sidebar, AnQi CMS provides a very intuitive and flexible way to achieve this.

2025-11-08

How to display the document list under the specified Tag label and implement pagination?

In AnQi CMS, the Tag (tag) function is an important tool for organizing and associating content, enhancing user experience and website SEO performance.When your website content becomes richer, how to effectively display the document list under a specified Tag and provide clear pagination navigation is crucial for the discoverability of content and the continuous browsing of users.This article will give you a detailed explanation of how to easily implement this feature by using several key template tags in AnqiCMS.

2025-11-08

How to get and display detailed information of a single Tag label (Title, Description, Logo)?

In AnQi CMS, tags (Tag) are an important way to organize and associate content.Sometimes, we need not only list the tags but also hope to display detailed information about a single tag on an independent page or in a specific area, such as its title, description, and even a representative logo.The AnQi CMS provides a concise and efficient method to meet this requirement. ### Understanding Tag Information Source In the Anqi CMS backend, you can configure the details for each tag.

2025-11-08