How to quickly view all available fields and values of the `categoryList` returned item object during template debugging?

Calendar 👁️ 67

During the development and debugging of AnQi CMS templates, we often need to gain a deep understanding of the data structure returned by template tags in order to control the display of page content more accurately. Especially likecategoryListsuch list tags, it will loop and output multiple timesitemobjects, eachitemthey carry rich data. So, how can we quickly and comprehensively viewcategoryListreturneditemWhat fields and their corresponding values are included in the object?Don't worry, as an experienced website operations expert, I will reveal several efficient methods to help you navigate the Anqi CMS template world with ease.

UnderstandcategoryListthe returned data structure is crucial

categoryListThe tag in AnQi CMS is mainly used to obtain the list of category data, it supports filtering out the category set that meets the conditions according to parameters such asmoduleId(Model ID),parentId(parent category ID) and others. When we use{% for item in categories %}such loop structure while iterating,itemrepresents the detailed data object of each category. To effectively utilize these data, we first need to knowitemWhat treasures are in this object.

Method one: utilizedumpFilter, see everything at a glance (highly recommended)

In the Anqi CMS template engine, a very practical one is built in.dumpA filter that prints the structure type and value of a variable in full. It is a real lifesaver for debugging dynamic data.

Operation steps:

  1. In your template file (for examplecategory/list.htmlorindex.htmlcall incategoryListat position) find{% for item in categories %}inside the loop body.
  2. Add a line of code inside the loop toitempass the object throughdumpa filter output:
    
    {% categoryList categories with moduleId="1" parentId="0" %}
        {% for item in categories %}
            <pre>{{ item|dump|safe }}</pre>
            {# 正常展示分类信息的代码,例如: #}
            <h2><a href="{{ item.Link }}">{{ item.Title }}</a></h2>
            <p>{{ item.Description }}</p>
            {# ... 其他分类字段 ... #}
        {% endfor %}
    {% endcategoryList %}
    
  3. Refresh your page. You will see eachitemobject's detailed structure and current value, they are<pre>Label wrapping for better readability.

Why recommenddumpFilter?

  • Comprehensiveness:It will print outitemAll fields included in the object, including those internal fields or custom fields that may not be explicitly listed in the document.
  • Real-time:Directly reflects the currentitemActual data of the object at page rendering, convenient for troubleshooting data issues.
  • Intuitiveness:Clear output format, easy to understand the level of the object and the values of each field.

Special attention is needed here.|safeThe usage. IfdumpThe filter output may contain HTML tags (for example, some field values are themselves HTML fragments), without adding|safeMay be displayed as plain text by the browser. AlthoughdumpThe output is typically a variable structure, free of malicious HTML, but for safety's sake, or when you see certain characters in the output (such as</>), add the|safeThe filter ensures that the output content is parsed and displayed as is.

Method two: refer to the official documentation and follow the instructions.

AnQi CMS provides a comprehensive template tag document, which is the most fundamental and authoritative reference for our template development. Specifically,categoryListthe tags returned byitemObject, the document clearly lists the commonly used available fields.

Check the path:

  1. In the Anqi CMS help document, find the "template call tags" under the "category page tags" section.
  2. Click to enter the 'Category List Tag'categoryListDetailed description page (i.e.,tag-/anqiapi-category/151.html)
  3. You can find in this page, such as “itemAvailable fields for the variable in the for loop body

The document usually lists the following key fields:

  • Id: The unique identifier ID of the category.
  • Title: The title name of the category.
  • Link: Category access link.
  • DescriptionCategory description.
  • Content: Detailed content of the category (if filled in on the back end).
  • ParentId: The ID of the parent category, used to build the hierarchical relationship.
  • LogoThe thumbnail large image address of the category.
  • ThumbCategory thumbnail image address.
  • SpacerUsed to display the prefix of the sub-category at the classification level (e.g., indentation symbol).
  • HasChildrenA boolean value indicating whether the category has a sub-category.
  • IsCurrentA boolean value indicating whether the category is the category of the current visited page.
  • ArchiveCountThe number of documents contained under the category.

The advantage of this method lies in:

  • Authoritativeness:The document is the most accurate field definition.
  • Purpose:Fields usually have clear meanings and usage descriptions.

However, the document may not cover all internal fields or additional fields generated under specific versions or custom models. Therefore, combinedumpFilter usage can provide a broader perspective.

Tips in practical application

  • Conditional judgment:After obtaining the field, it can be utilized{% if item.HasChildren %}This way to judge whether there is a subcategory, thus deciding whether to display the submenu or perform other operations.
  • Data formatting:ForContentfield, if it contains Markdown content, you can refer totag-/anqiapi-category/152.htmlmentionedrender=trueparameters to control rendering. For image links, you can use|thumbfilter to generate thumbnails.
  • dynamic display:Flexible applicationitem.Linkanditem.Titlefields, build dynamic category navigation and content list.

By combining the use of the above two methods, you will be able to obtain quickly and accurately.categoryListreturneditemAll available fields and values of the object, thus more efficiently carrying out the development and debugging of security CMS templates.

Frequently Asked Questions (FAQ)

Q1: Why do I usedumpAfter the filter, the output result is garbled or incomplete?

A1: If the output results in garbled text, first check if your template file is saved in UTF-8 encoding format.The AnQi CMS defaults to using UTF-8 encoding for template files.Secondly, if the output result is incomplete, it may be due to the output content being too long or containing some special characters that cause the browser to parse errors.You can try todumpPaste the output content into a code editor (such as VS Code). They usually handle long text and special characters better. Also, make sure you are using|safeFilter to prevent potential HTML escaping issues.

Q2:categoryListreturneditemWithin the objectContentField, how to control Markdown rendering?

A2:categoryListreturneditem.ContentThe field itself only contains the original text content. If you want to display the content rendered with Markdown in a category list, you need to usecategoryDetailthe tag as follows to obtainContentwhen callingrender=trueThe parameter. For example, you can first go throughcategoryDetailto get the Markdown rendering content of a specific category, orcategoryListin the loop, for eachitemuse first, and then usecategoryDetailLabel and pass in.item.Idto get the rendering options withContent.

Q3: BesidescategoryListsuch as other list labelsarchiveList/pageList)的itemDo object fields also have similar methods to view?

A3: Yes, it is fully applicable!dumpThe filter is a general feature of Anqi CMS template engine, applicable to any variable whose internal structure and value you want to view. Whether it isarchiveListreturnedarchivean object orpageListreturnedpageObject, you can use it inside the loop{{ item|dump|safe }}to view all available fields. At the same time, you can also likecategoryListto consult the official documentation of the corresponding tag (such astag-/anqiapi-archive/141.html/tag-/anqiapi-category/154.html) to get itsitemThe field list of the object. This will greatly accelerate your debugging efficiency in the Anqi CMS template development.

Related articles

Can the `moduleId` parameter of the `categoryList` tag specify multiple model IDs for a union query?

As an experienced website operations expert, I have a deep understanding of the powerful functions and flexible template system of AnQiCMS (AnQiCMS).In daily content operations, we often encounter the need to aggregate and display different types of content.Today, let's delve into the usage of the `categoryList` tag's `moduleId` parameter, especially the issue of whether it can specify multiple model IDs for a joint query.

2025-11-06

How to implement the display of the 'sibling categories' of the current category in `categoryList`, instead of the subcategories?

AnQi CMS is an efficient and customizable content management system, playing an important role in website operations.Its template system is powerful and flexible, allowing operators to finely control the display of content according to actual needs.Today, let's delve into a common issue in actual operation that beginners may find confusing: how to cleverly display 'sibling categories of the current category' in the `categoryList` tag, rather than its subcategories.It is of great significance to display the brother category list in terms of content organization and user experience.

2025-11-06

`categoryList`Does it support filtering or displaying based on custom fields by category?

HelloAs an experienced website operations expert, I know the importance of a flexible content management system for efficient operations.AnQiCMS stands out among many CMS systems with its excellent customizability, especially in content modeling and category management, providing great convenience.However, many operators may wonder a question when using the `categoryList` tag: does it support filtering or displaying based on custom fields of categories?

2025-11-06

How to display different content in the `categoryList` loop based on the different `moduleId`?

As a senior website operations expert, I fully understand that the flexibility of content presentation is crucial for user experience and operational efficiency.AnQiCMS (AnQiCMS) relies on its powerful template engine and content model mechanism to provide us with a powerful tool for achieving this flexibility.Today, let's delve into a very practical scenario: how to intelligently display distinctive content according to different `moduleId` in the `categoryList` loop.

2025-11-06

`categoryList`How to use the `empty` tag block when no categories are found, and how to customize prompt information?

As an experienced website operations expert, I know that every detail in the presentation of website content may affect the user experience and the professional image of the website.Especially in the scenario where data is "missing", how to avoid making the page look stiff, blank, or even confusing to users is a task that requires careful design.Today, let's delve into how to skillfully use the `empty` tag block to customize friendly prompt information when the `categoryList` tag in AnQi CMS does not find any category data.

2025-11-06

Is the `categoryList` tag returning categorized data real-time from the database or does it have an in-built caching mechanism?

In the daily operation of website management, the speed and efficiency of data access are core elements of user experience and search engine optimization.For systems like AnQiCMS (AnQiCMS) that are dedicated to providing efficient and customizable content management solutions, whether the internal data processing mechanism, especially tags like `categoryList` that are frequently called, always directly query the database or have an intelligent caching mechanism, is a focus of many operators.

2025-11-06

How to limit the display quantity of each subcategory level when nesting multi-level categories?

AnQiCMS is an efficient and flexible content management system that excels in building structured content, especially its multi-level classification feature, which helps us clearly organize website content.However, when displaying multi-level category nesting, we often encounter a challenge: how to elegantly control the display quantity of each sub-category level to avoid the page being too long or the load being too heavy?As an experienced website operation expert, I am well aware of the importance of this requirement. Today, I will delve into the exquisite way to achieve this goal in AnQiCMS with everyone.

2025-11-06

What is the corresponding relationship between the `categoryList` tag and the classification related fields in the background `content model` settings?

As an experienced website operations expert, in my practice with AnQiCMS, I deeply understand that its flexible and powerful content management capabilities are the cornerstone of website success.Today, let's delve into a seemingly simple but highly flexible core mechanism: the `categoryList` tag and the correspondence relationship of classification-related fields in the background `content model` settings.Understanding this can help you control the presentation of website content more finely, realizing truly customized operation strategies.

2025-11-06