How to handle the `extra` field returned by the `archive/list` interface to obtain custom field information?

Calendar 👁️ 83

When using AnQi CMS for website content management, we often need to display more personalized data in addition to the conventional information such as title, introduction, thumbnail, etc.This additional information, such as the author of the article, the model of the product, the release location, etc., is achieved through the powerful custom field function of Anqicms.So, when we go through the front-endarchive/listHow can you elegantly extract and utilize these custom fields when fetching the document list through the interface? The answer is hidden in the returned data.extrathe field.

Inarchive/listIn each document returned by the interface (or called an article) data, you will find a field namedextraThe field. This field is like a treasure chest, containing all the custom field information you have carefully set for the document.extraThe field itself is an object (or sometimes called an associative array), the key (key) is the form field call name you set in the Anqi CMS background content model, and the value corresponding to each key is another object containingname/valueanddefaultAn object with three properties.

Let us understand through a specific example. Suppose you add a custom field named "author" in the "article" content model in the Anqi CMS background, and it internally calls a named author. When you pass througharchive/listWhen you retrieve the list of articles through the interface, if an article has filled in author information, then in itsextrafield, you will see a structure similar to this:

"extra": {
  "author": {
    "name": "作者",
    "value": "AnqiCMS编辑部",
    "default": ""
  },
  "publish_city": {
    "name": "发布城市",
    "value": "上海",
    "default": "北京"
  }
}

Here, authorandpublish_cityIs the name of the custom field call. They each contain:

  • name: The Chinese display name of the field, convenient for understanding.
  • value: This document is the actual content filled in for this custom field.
  • defaultIf:valueIf left blank, this default value will be used.

It is very intuitive to obtain the values of these custom fields. You just need to use the "call name" of the field (that is,extraTo access it, then retrieve thevalueproperty. For example, if you have already obtained a single document object in your frontend codedocumentThe way to get the author's name isdocument.extra.author.valueTo get the publishing city isdocument.extra.publish_city.value.

This feature greatly enhances the flexibility and scalability of content. By customizing fields, you can add exclusive attributes that fully meet the business needs of different content models (such as articles, products, cases, etc.) andextraThe field is the key to passing these exclusive attributes from the backend to the frontend.This means you can design highly customized display pages based on the content model, without changing the core code to adapt to diverse content structures.

In actual development, there are several points to pay special attention to. First, be sure to checkextraWhether the field itself and its internal custom fields exist. Some documents may not have filled in a certain custom field, or the field may not be defined at all in the content model, in which case it is accessed directly.document.extra.someField.valueIt may cause the program to crash. A robust approach is to first determineextrawhether it exists, then determine whether the specific custom field exists, and finally try to retrieve itsvalueFor example, conditional statements can be usedif (document.extra && document.extra.author) { /* 使用 document.extra.author.value */ }to ensure the robustness of the code. Secondly, whenvaluethe field is empty, consider usingdefaultthe field as a backup display content to enhance user experience.

Furthermore, if you not only need to get the value of a custom field, but also want to know its type (such as text, number, or image), or whether it is a filterable field and other metadata information, then you can further utilize the services provided by Anqi CMS.module/detailThe interface can return the detailed definitions of all custom fields of the specified content model, including theirfield_name/name/type/is_filterProperties such as this are very useful for front-end dynamic form rendering or different handling based on field type.

In summary,archive/listThe interface returnsextraThe field provides a unified and flexible mechanism for handling custom field information in Anqi CMS.Understand and make good use of this mechanism, it will make your website content display more depth and personalization, thereby better meeting user needs.


Frequently Asked Questions (FAQ)

1.extraWhy are fields sometimes empty(null)?When you do not set any custom fields for the document type in the Anqi CMS backend content model, or although fields are set, all custom fields in the document instance are not filled in with any values (including default values), thenarchive/listThe interface returnsextraField may display asnullIt is recommended to check in the frontendextraWhether the field isnullTo avoid errors caused by attempting to access the properties of an empty object.

2. How to know the 'calling name' of a custom field (field_name)?The "display name" of a custom field is the unique identifier you set when creating or editing the content model in Anqicms background.If you forget the name of a field's call, you can enter the corresponding content model management interface in the background to view it.Furthermore, you can also callmodule/detailinterface (pass the corresponding model ID) to get the detailed definitions of all custom fields under the model, includingfield_nameProperty.

3.extrafields indefaultWhat is the value for? defaultThe value is in the custom field.valueA placeholder value provided when nothing is specified. For example, if you set up a "author" field and specify the default value "anonymous", then when a document does not explicitly fill in the author,extra.author.valueMay be empty, butextra.author.defaultWill still be "Anonymous". This can be used as a fallback option when displaying content, ensuring that even if no specific information is filled in, there is a friendly prompt or preset content.

Related articles

How to use the `q` parameter to perform keyword search in the AnQiCMS document list and realize the in-site search function?

In the daily operation of a website, providing users with an efficient and convenient in-site search function is a key factor in improving user experience and guiding content discovery.For those of us using AnQiCMS to manage website content, it is not difficult to achieve this function.AnQi CMS provides a very practical parameter——`q`, which allows us to easily search for keywords in the document list.### Start the in-site search journey: Understanding the `q` parameter In the AnQiCMS document list interface (/api/archive/list), `q`

2025-11-09

How does the `child=false` parameter affect the display of categories and their subcategories when retrieving the document list?

In Anqi CMS, the `archive/list` interface is the core tool for obtaining the list of website documents, which provides a variety of parameters to help us accurately filter and display content.Among them, the `child` parameter, although simple in appearance, plays a vital role in the display of categories and their subcategories in documents, directly affecting the granularity of content presentation.Understand and make good use of this parameter, it can make the content organization of your website clearer and improve the user experience.By default, when you access `archive/list`

2025-11-09

How to get the document list with 'Headline' or 'Slide' recommended attributes (`flag`) in AnQiCMS?

In AnQiCMS (AnQiCMS), content managers often need to flexibly display important content on the website, such as setting specific articles as 'headline' or 'slideshow' to attract users' attention.The AnQi CMS provides a very practical feature, that is, marking documents through the 'recommended attribute' (flag).If you want to get the list of documents marked specially, the AnQiCMS API interface can help you achieve it easily.

2025-11-09

Does the AnQiCMS document list interface support excluding multiple categories of documents at the same time (`excludeCategoryId` usage)?

In website operation, we often need to flexibly display content, such as displaying the latest articles on a page, but not including content under certain specific categories, such as announcements or internal news.AnQiCMS as a powerful content management system, provides a rich set of API interfaces to meet these complex display requirements.Today, let's delve into a very practical parameter of the `archive/list` interface: `excludeCategoryId`, especially how it supports excluding multiple categories of documents.###

2025-11-09

In the AnQiCMS document list, what do the `images`, `logo`, and `thumb` fields represent, and how should they be used?

When using AnQi CMS to manage website content, we often encounter scenarios involving image upload and display.In the data structure of documents (articles, products, etc.), categories, and even single pages, the `images`, `logo`, and `thumb` fields play different roles. They work together to support the effective presentation and performance optimization of the website's visual content.Understanding their specific purposes can help us better plan content and optimize the user experience.### `images` : multi-image display and rich content `images`

2025-11-09

How to build pagination navigation for AnQiCMS document list on the front-end page (using `page` and `total` parameters)?

When displaying a large number of documents on the website frontend, pagination navigation is a key feature for improving user experience and managing data loading efficiency.AnQiCMS (AnQiCMS) provides a powerful and flexible API interface, allowing you to easily implement pagination of document lists on the front end.This article will introduce in detail how to use the `page` and `total` parameters in the `archive/list` interface to build a fully functional pagination navigation.--- ### Understanding the core of AnQi CMS pagination mechanism To build pagination navigation for the document list

2025-11-09

How to use the `type=related` mode in the AnQiCMS document list interface to get related articles?

In website content operation, providing users with relevant article recommendations is an important strategy to enhance user experience, extend visit duration, and optimize content discovery.The AnqiCMS document list interface (`archive/list`) provides a very convenient feature, which can be easily achieved by setting the `type=related` parameter.### Understanding the `type=related` mode After a user has finished browsing a document (article, product, etc.), they usually want to find more information that is thematically similar and complementary to the current content.

2025-11-09

Is the `created_time` and `updated_time` returned by the AnQiCMS document list a Unix timestamp, and how do I convert it to a readable date?

When using AnQiCMS, we often retrieve detailed information or lists of documents or other content from the API interface.In these returned data, `created_time` (creation time) and `updated_time` (update time) are two very critical fields.Many users may be curious, what are these values that look like a string of numbers?They are actually standard Unix timestamps. ### Understanding Unix Timestamps Unix timestamp, also known as Posix time

2025-11-09