Does the `moduleDetail` tag support direct retrieval of custom field values defined in the content model, and if so, how do you call it?

Calendar 👁️ 95

As an experienced website operations expert, I am well aware of the importance of a flexible content model and convenient template calls for a modern CMS.AnQiCMS (AnQiCMS) performs well in this regard, its powerful template tag system makes content presentation both flexible and efficient.Today, let's delve deeply into a question that everyone cares about: moduleDetailDoes the tag support directly retrieving the value of the custom field defined in the content model? If so, how can it be called?

First, let us clarify the division of responsibilities among different tags in Anqi CMS. Anqi CMS divides the data in the content management system into several levels:

  1. Data at the system level: Such as website name, Logo, contact information, etc., these are throughsystem/contacttags.
  2. Data at the content model levelThis refers to the metadata of the content model itself, for example, the name, alias, and the table name corresponding to it in the database, etc. This information is exactlymoduleDetailThe tag is responsible for fetching.
  3. Document (content) level dataThis refers to a specific document published through a certain content model (such as a news article, a product detail), including the document title, content, publishing time, as well asIn this content model, an additional custom field is defined for the document.

Understanding this hierarchy, we can better understandmoduleDetailThe function of tags. According to the Anqi CMS document description,moduleDetailLabels (for example intag-/anqiapi-category/3501.html) are mainly used to obtain the details of the content model itself, such as:

  • Model ID(Id)
  • Model title(Title)
  • Model name(Name)
  • Model Link(Link)
  • Model table name(TableName)
  • Model Introduction(Description)

This information is about the content modelitselfThe attribute, rather than the custom fields owned by the specific document under the model. In other words,moduleDetailIt is used to describe what the 'article model' is like, rather than what specific field values an article has.

Then, when we want to obtain the 'content model' ofSpecific documentWhat tag should be used when defining a custom field value? The answer is:archiveDetailandarchiveParams.

The strength of AnQi CMS lies in its 'flexible content model' feature (such asAnQiCMS 项目优势.mdMentioned), allowing users to customize the content structure according to business needs, such as adding an "author introduction" field to the "article model" or adding "product size", "color", and other fields to the "product model". These custom fields are attached toSpecific document content.

How to obtain the value of the custom field defined in the document?

AnQi CMS provides two main ways to call the document (archive) to obtain the value of the custom field:

  1. Direct pass.archiveDetailLabel calls a single custom fieldIf you know the name of the custom field's 'call field' (defined in the backend content model management, for exampleauthor_info), and you can directly access the value of a specific custom field in the documentarchiveDetailLabel. For example, you define a field namedauthor_infoYour custom field, you can call it like this on the article detail page:

    <div>作者简介:{% archiveDetail with name="author_info" %}</div>
    

    If the current page context already hasarchiveVariable (usually available on the document detail page), you can also access it more succinctly through a variable:

    <div>作者简介:{{ archive.author_info }}</div>
    

    This method is very suitable when you know exactly which custom field to display.

  2. ByarchiveParamsLabel traversal or retrieve all custom fields by nameIf you need to get all the custom fields of the current document, or your custom field is a complex type (such as a multi-image group, a multi-choice box),archiveParamsTags provide more powerful features. For example,tag-/anqiapi-archive/146.htmlas shown in the documentation,archiveParamsTags will return a collection containing all custom fields. You can control the returned data structure through thesortedparameters:

    • sorted=true(default): Return an ordered array, you can go throughforLoop through all custom fields. This is very useful when you need to dynamically render all parameters and their values in a template.
      
      {% archiveParams params %}
      <div>
          {% for item in params %}
          <p><strong>{{ item.Name }}:</strong>{{ item.Value }}</p>
          {% endfor %}
      </div>
      {% endarchiveParams %}
      
      Hereitem.NameIs the field display name (such as "author biography"),item.ValueIs the specific value of the field.
    • sorted=false: Returns an unordered map object, you can directly access its value by using the 'field name' of the custom field, just like accessing the properties of an object.
      
      {% archiveParams params with sorted=false %}
      <div>
          <p>作者简介:{{ params.author_info.Value }}</p>
          <p>出版日期:{{ params.publish_date.Value }}</p>
      </div>
      {% endarchiveParams %}
      
      It is particularly noteworthy that when your custom field is of the 'gallery' type, it may store an array of image URLs. At this point, you need to first go througharchiveDetailorarchiveParamsGet this array and then use itforLoop to traverse and display the image:
    {# 假设你的组图自定义字段名为 'product_images' #}
    {% archiveDetail product_images with name="product_images" %}
    <div class="product-gallery">
        {% for img_url in product_images %}
        <img src="{{ img_url }}" alt="产品图片">
        {% endfor %}
    </div>
    

    If your custom field contains rich text content (such as a 'detailed description' field that includes HTML tags), be sure to include it in the output.|safeA filter to ensure that HTML content can be parsed correctly rather than being escaped:

    {% archiveDetail with name="long_description" %}{{ long_description|safe }}
    

Summary

moduleDetailTags and getting custom field values are two different levels of concepts.moduleDetailThe focus is on the structure and metadata of the content model itself, whereas the values of the custom fields defined within the content model need to be accessed througharchiveDetailorarchiveParamsthese tags because the values of these fields are associated withThe specific document (archive)Closely related. Correct understanding and application of these tags can enable you to achieve high customization and flexible content display in Anqi CMS.


Frequently Asked Questions (FAQ)

Q1: I defined a custom field called "Product Specifications" in the content model, should I usemoduleDetailOrarchiveDetailto display it on the product detail page?

A1:you should usearchiveDetailLabel. Because "Product specifications" is fora specificproduct documentation, its value may vary from product to product.moduleDetailThe label can only retrieve the attributes of the "product model" concept itself (such as the name "product model"), and cannot retrieve the "product specification" value of a specific product document. You can call it like this:{% archiveDetail with name="产品规格的调用字段名" %}.

Q2: If I have a content model with dozens of custom fields, how can I list them all without writing them one by onearchiveDetailWhat about the tags

A2:This isarchiveParamsThe place where tags can be used. You can use{% archiveParams params %}tags to get all the custom fields of the current document, it will return an array containing information about these fields. Then you can use aforLoop through this array to dynamically display the names and values of each field without manually listing each field. For example:

{% archiveParams params %}
{% for field in params %}
  <p>{{ field.Name }}:{{ field.Value }}</p>
{% endfor %}

Q3: My custom field is 'Product Group Image', which stores multiple images. I usedarchiveDetailgot the value, but it only displays a string of text and not the images. What's the matter?

A3:When you define a custom field of the "Group Image" type in the content model, Anqicms will store these image URLs in the form of an array.Directly outputting the array will display its text representation. To correctly display the images, you need to pass the array of obtained image URLs through anforLoop to iterate through and then generate one for each URL<img>Label. For example: “`twig {% archiveDetail product_gallery_images with name=“product_images_field_name” %}

Related articles

How to retrieve the database table name (`TableName`) of the content model in a template for a custom query?

As an experienced website operations expert, I deeply understand the powerful capabilities brought by the flexible content model in AnQiCMS through my practice.Many times, we not only need to display the content itself, but also need to drive deeper page logic or style based on the type of content.Today, let's delve deeply into a seemingly minor but crucial feature: how to obtain the database table name (TableName) of the content model in AnQiCMS templates, thus achieving more refined custom control.--- ###

2025-11-07

What is the difference and usage of the `Title` and `Name` fields in the content model in practice?

In the daily operation of AnQiCMS, we often encounter content models and their fields.Among the field names "Title" and "Name", which seem similar, there are completely different responsibilities in practical application.As an experienced website operations expert, I fully understand the importance of understanding these subtle differences for efficient content management, optimizing website structure, and improving user experience.

2025-11-07

If my AnQi CMS is a multi-site deployment, how to use the `moduleDetail` tag to retrieve the content model data of other sites?

AnQi CMS is an enterprise-level content management system designed specifically for small and medium-sized enterprises, self-media, and multi-site management, and its multi-site management capabilities are undoubtedly one of the core highlights.In daily operations, we often encounter such scenarios: we hope to display certain information of the child site on the main site, or to cross-reference content or data models between different sites.Today, let's delve into a specific and practical scenario - how to use the `moduleDetail` tag to obtain content model data from other sites in a multi-site deployed Aiqi CMS.###

2025-11-07

How to retrieve information about a specific model through the content model's URL alias (`token`)?

## How to skillfully use AnQiCMS content model URL alias (`token`): The wisdom of accurately obtaining information As an experienced website operations expert, I am well aware of the importance of an efficient and customizable content management system for enterprise websites and content operation teams.AnQiCMS with its efficient architecture in Go language and versatile functions is gradually becoming a powerful assistant for many operators.In daily content management, we not only strive for the quality presentation of content, but also need efficient data access and management. Today

2025-11-07

How to determine if the current page belongs to a specific content model (such as 'article model'), and display different content accordingly?

As an experienced website operations expert, I know that flexible content display is crucial for the operational efficiency and user experience of a website.In a powerful content management system like AnQiCMS, understanding how to display differentiated content based on different content models is a key step in achieving refined operation.Today, let's delve deeply into this topic and reveal how AnQiCMS can help us easily achieve this goal.

2025-11-07

When creating a new content model, what are the naming restrictions and practices for the `model table name`?

## Build an Efficient Content Model: The Art and Practice of Naming `Model Table Name` in Anqi CMS As an experienced website operations expert, I fully understand that every detail in a content management system can affect the performance, stability, and future scalability of a website.AnQiCMS (AnQiCMS) provides strong support for building a diverse content structure with its flexible content model features.However, when customizing content models, a seemingly trivial aspect - the naming of the `model table name`, entails many limitations and**practical considerations, worthy of in-depth exploration

2025-11-07

How should the `URL alias` of the content model be set to better support the `{module}` variable in the SEO static rules?

## Unlock AnQiCMS SEO Potential: The Clever Combination of Content Model URL Aliases and Permalinks In today's highly competitive online environment, whether a website can stand out in search engines largely depends on the implementation of its SEO optimization strategy.As an experienced website operations expert, I am well aware of the importance of URL structure for SEO.A clean, meaningful, and SEO-friendly URL is the foundation for improving website ranking.

2025-11-07

What impact will modifying the `URL alias` of the content model have on the existing page URL structure?

Good, as an experienced website operation expert, I am willing to delve into the impact and coping strategies of modifying the content model 'URL alias' in AnQi CMS.In AnQi CMS, such an efficient and flexible content management system, the setting of `URL alias` seems trivial, but in fact, it affects the whole body, especially in content operation and SEO, its impact should not be overlooked.

2025-11-07