How does the key-value pair structure (`key => item`) in the document details correspond to the backend custom field settings?

Calendar 81

When using AnQi CMS to manage website content, the document details or document list interface (such asarchiveDetailandarchiveList) will often return data with a field namedextraThe field. This field is specifically used to carry the custom information we set for the document model. UnderstandextraThe structure of the field and its correspondence with the backend custom fields is crucial for frontend development and content management.

Understanding the custom field mechanism of AnQi CMS.

The AnQi CMS provides powerful custom field functionality, allowing users to flexibly expand their properties based on different types of documents (such as articles, products, etc.).In the background, when you enter "Model Management" and select a specific document model (such as "Article Model" or "Product Model"), you can add or edit custom fields for the model.

Each custom field when set in the background, there are several core properties that need to be paid attention to:

  • Field name (field_name)This is the unique identifier for the field within the system, and it is also used in the field when we make API requests, inextrathe field askeyThe identifier. It is usually an English word or pinyin, such as 'author', 'city', 'certificate', etc.
  • Field Chinese Name (name): This is a friendly name displayed on the back-end interface for content editors, such as "author", "publishing city", "education", and so on.It helps us intuitively understand the purpose of the field.
  • Field Type (type): Determines the data type that the field can store, such as text (text), number (number), radio (radio), checkbox (checkbox), image (image), and so on.
  • Is filtering (is_filter): Mark whether this field can be used as a front-end filtering condition.
  • Default value (default/content): The initial value set for this field.

It is through these background configurations thatextrathe field is dynamically presented in the API response.

extrathe structure of the field is parsed.

When we go througharchiveDetailorarchiveListWhen the document data is obtained through the interface, if the model associated with the document is configured with custom fields, the data of these fields will be packaged intodataobject underextrain the field.

extraThe structure of the field iskey => itemin the form of:

  • keyHere is thekey directly corresponds toYou are in the background custom field settingsThe field name (field_name). This is the unique identifier used by front-end developers to accurately access a custom field value. For example, if you set a custom field in the back end,field_nameWithauthorthen inextraIn the field, you will see a namedauthorkey?
  • item: withkeyassociateditemIt is an object that contains detailed information and actual content of the custom field, usually including the following properties:
    • nameThis corresponds to the field Chinese name you set in the background. For example, ifkeyIsauthorthennameit might be 'author'. It is mainly used for display and understanding.
    • valueThis is the actual content filled in or stored in the current document in this custom field. This is the data we most often need to extract and display.
    • defaultThis property displays the default value set for this custom field in the background.

Let us illustrate this with an example:

"extra": {
  "author": {
    "name": "作者",
    "value": "AnqiCMS",
    "default": ""
  },
  "certificate": {
    "name": "学历",
    "value": null,
    "default": null
  },
  "city": {
    "name": "城市",
    "value": "北京\n上海\n重庆",
    "default": "北京\n上海\n重庆"
  }
}

We can clearly see from this returned data thatauthor/certificate/cityThesekeyThey are the field names we define in the background for the custom fields of the model. EachkeybelowitemThe object also lists in detail the Chinese name of the fieldname), and the actual content (value)and \default)。For example, to get the author\'s name, we simply need to accessextra.author.valueJust do it.

Application scenarios in practice

ThisextraThe mechanism of field and custom field correspondence brings great flexibility to the content management and front-end display of the website:

  1. Dynamic content display: The front-end can useextrafields inkeyRender page content dynamically without modifying the backend code or database structure. Regardless of how many custom fields are added to the backend, the frontend can access and display them through a unifiedextrastructure.
  2. Filter and SearchIf a custom field is marked as “filterable”(is_filter=true),then you will also see it inarchiveFiltersthe interface.field_nameThis allows the front-end to build complex filters, allowing users to retrieve documents based on the values of these custom fields, thereby providing a more refined content navigation experience.
  3. Data import and publication: PassedarchivePublishorimportArchiveWhen publishing or importing a document, the data of the custom fields can also be submitted as part of the request parameters. At this time, the name of the request parameter key should also match the "field name" defined on the back-end. ...field_nameKeep consistent.

Through this design, Anqi CMS perfectly combines the flexibility of content management with the standardization of API data transmission, allowing website operators to easily expand the content model and also providing developers with a clear and predictable data structure.


Frequently Asked Questions (FAQ)

1. If I delete a custom field in the background, will it still be included in the API response?extraWill the field still contain it?Answer: No.extraThe field is dynamically generated and it will only contain the custom fields that exist in the current model and have content filled in the document. Once a custom field is deleted from the background or there is no content filled in the field in the document, the field will not be displayed.extraThis value appears in the field.

2.extrafields invalueWithnullWhat does this mean? How should I handle it?Answer:valueWithnullIndicates that the custom field for this document is not filled in on the backend. If a default value is set for this field in the backend,defaultthe property may display the default value, butvalueit will still benullunless the actual content is filled in. When handling on the front end, it should be checked.valueIs itnullto decide whether to display the default value, display empty content, or perform other logical operations.

**3. I can in `

Related articles

How to handle the display of front-end images if the `thumb` or `logo` field returned by the document detail interface is empty?

When building a website with AnQiCMS, we often retrieve detailed document information from the backend interface.Among them, images are an indispensable part of content display, and the `thumb` (thumbnail) and `logo` (logo) fields are particularly important, as they are usually used in article lists, the top or sidebar of detail pages, and other locations.However, in actual development, we may encounter situations where these fields return empty.How should we handle it elegantly when the front-end gets an empty value, to ensure the friendliness of the user interface (UI) and the integrity of the content

2025-11-09

How to use the `url_token` in the `category` object to build the link of the category?

Building clear and accessible links for your website content in Anqi CMS is a key factor in optimizing user experience and search engine rankings.Among them, using the `url_token` in the `category` object to build category links is an efficient and SEO**compliant method.Understand the role of `url_token` in category links `url_token` is a unique identifier provided by Anqi CMS for each category, usually a short, descriptive English word or pinyin

2025-11-09

Why does the document detail have `price` and `stock` fields, even though the document is not a product type?

When using AnQiCMS to manage website content, many users may notice a phenomenon: even for ordinary articles, news, and other non-product type documents, the returned data structure still contains the `price` (price) and `stock` (inventory quantity) fields when their details are retrieved through the API.This may seem confusing at first glance, but after understanding the design philosophy of AnQiCMS, it will be found that this is exactly the embodiment of its powerful flexibility and scalability.AnQiCMS is designed at the bottom level

2025-11-09

If multiple recommended properties exist in the `flag` field (such as 'hc'), what characteristics does the document have simultaneously?

How to make important information stand out in the vast sea of content on a website and be discovered by users first is the focus of every operator.AnQiCMS (AnQiCMS) provides us with a very flexible and powerful tool for managing the display priority and characteristics of content - that is the `flag` field.This little field, yet contains huge potential for content operation.The mystery of the `flag` field: the叠加effect of multiple attributes In Anqi CMS, the `flag` field plays the role of document "recommended attribute" or "characteristic mark".

2025-11-09

How to query all custom field information contained in a model (such as an article model)?

The Anqi CMS, with its powerful content model and flexible custom field features, provides great convenience for website operators.These custom fields are the key to the personalization and data structuring of website content.How can you accurately query all the custom field information contained in a specific model (such as an article model)?This is very useful when performing secondary development, data connection, or just to understand the system structure.

2025-11-09

How to implement reading level control for specific documents (such as paid documents) in Anqi CMS?

In AnQi CMS, implementing a reading level control (`read_level`) for specific documents (such as paid documents or exclusive member content) is a very practical feature. It helps us better manage content permissions and achieve differentiated content operations.This mechanism is not only flexible, but also closely integrated with the user system, allowing us to determine what content users can see based on their identity or payment status. Next, we will explore how to efficiently use `read_level` in Anqi CMS to implement document access control.###

2025-11-09

How should the comment area on the document detail page be integrated with the Anqi CMS comment API to display and publish comments?

In website operation, the comment area of the document detail page plays an important role, it not only promotes user interaction and enhances content activity, but also brings new content and search engine visibility to the website.AnQiCMS provides a powerful and easy-to-integrate comment API that allows you to easily implement comment display and posting features on your website.This article will discuss in detail how to use these APIs to create a fully functional comment system for your document detail page.##

2025-11-09

How to optimize the navigation experience of the previous and next documents through the `archivePrev` and `archiveNext` interfaces?

Today, with the increasing refinement of content management, every detail of a website may affect the reading experience of users.Among them, the navigation between the previous and next documents, as an important part of guiding users to continuously explore the website content, should not be overlooked in terms of convenience and fluidity.AnQiCMS (AnQiCMS) knows this and provides the powerful and intuitive interfaces `archivePrev` and `archiveNext` to help us easily implement and optimize this feature.###

2025-11-09