How to display custom field content on the AnQiCMS document detail page?

Calendar 👁️ 70

When managing website content in AnQiCMS, we often encounter the need to add some unique information for different types of documents (such as articles, products, etc.).AnQi CMS provides flexible content model features, allowing us to customize fields to meet these personalized needs.How can you display these custom fields after they are created and filled with data on the document detail page of the website?

This is actually simpler than you imagine, the powerful template tag system of AnQiCMS provides us with a variety of convenient ways to achieve this.


Step 1: Review the creation of custom fields

Before we start displaying custom fields on the detail page, we must first ensure that these fields have been correctly created in the content model of the AnQiCMS backend.Usually, we will enter the "Content Management" -> "Content Model" section of the background.Here, you can choose to edit an existing content model (such as 'Article Model' or 'Product Model'), or create a new one.

In the editing interface of the content model, there is an area for 'custom fields of the content model'.Here, we need to fill in the "Parameter Name" (this is the Chinese display name of the field, convenient for background management and understanding) and "Field Name" (this is the actual field name used in the template, usually in English).Understanding this 'call field' is crucial for subsequent data retrieval in the template.For example, if you add a field named "Product Features" to the product model, and its "call field" is set toproduct_featuresThen, in the template, we need to useproduct_featuresto get its content.

Step 2: Find the template file corresponding to the document details page

We need to modify the detail page template under the corresponding model to display custom fields. The AnQiCMS template files are usually stored in/templateUnder the directory, and organize according to the template package name and model type.

For example, the detail page template file of an article model may be located/{你的模板目录}/article/detail.htmlOr/{你的模板目录}/article_detail.html(The organization pattern of your template depends on your template organization mode). If you are not sure, you can refer to the section "Template Creation" -> "Directory and Template" in the AnQiCMS document for confirmation.

Step 3: Display the content of the custom field in the template

After finding the correct template file, we can start adding code to display custom fields.AnQiCMS provides two main ways to retrieve and display the content of custom fields: calling specific fields directly and looping through all custom fields.

1. Directly call a single custom field

If you know the 'invocation field' name of a custom field and want to display it only at a specific location on the page, you can usearchiveDetaillabel'snamespecify the parameter directly.

Assuming we added a custom field to the "article model", whose "access field" issource_author(Indicates the author of the article). In the document detail page template, we can display it like this:

<div>文章来源作者:{% archiveDetail with name="source_author" %}</div>

Or, if you have already passedarchiveDetail archiveThis way, all the information of the current document is assigned to a variablearchiveThen, it can also be accessed directly through dot syntax:

<div>文章来源作者:{{ archive.source_author }}</div>

This method is concise and clear, suitable for when you only want to display a few known custom fields.

2. Loop to display all custom fields

Sometimes, we may not be sure about the custom fields of a document model, or we may want to dynamically list all the additional information. At this time,archiveParamsLabels come into play. It allows us to retrieve the list of all custom fields in the current document and then display them through a loop.

This tag usually returns a list containing each custom field nameName) and value (ValueThe object array.

The following is an example of the code to loop through all custom fields in the template

{% archiveParams params %}
<div class="custom-fields">
    {% for item in params %}
    <div class="custom-field-item">
        <span class="field-name">{{ item.Name }}:</span>
        <span class="field-value">{{ item.Value }}</span>
    </div>
    {% endfor %}
</div>
{% endarchiveParams %}

In the code above:

  • {% archiveParams params %}Retrieve and store all custom parameters of the current document inparamsthe variable.
  • {% for item in params %}Traversalparamseach custom field in the array.
  • {{ item.Name }}Display the parameter name set in the background for the custom field.
  • {{ item.Value }}Display the specific content filled in for this custom field.

This method is very flexible, especially when you have a large number of custom fields in your content model, or when you want to reuse the same display logic across different document models.

3. Handle custom fields of specific types.

It is worth noting that the type of custom field affects its display on the front end:

  • Text field:Most text and numeric fields can be displayed directly{{ item.Value }}or{{ archive.your_field }}Display.
  • Rich text or Markdown field:If your custom field allows input of HTML or Markdown content (such as a complex 'product details' field), direct output may result in HTML tags being escaped. In order for the browser to correctly parse and render this content, you need to use|safeFilter, if the Markdown editor is enabled, it may also be required|renderfilter.
    
    {# 如果是HTML内容 #}
    <div>自定义富文本内容:{{ archive.rich_text_field|safe }}</div>
    {# 如果是Markdown内容 #}
    <div>自定义Markdown内容:{{ archive.markdown_field|render|safe }}</div>
    
  • Image field:If the custom field is an image type, itsValueIt is usually a URL of an image. You can treat it as a normal image and<img>label'ssrcDisplay properties.
    
    {# 假设自定义字段 'product_image' 存储图片URL #}
    <img src="{{ archive.product_image }}" alt="产品图片" />
    

By following the above method, you can easily display various custom field content on the document detail page of AnQiCMS.This makes your website content more rich and personalized, giving full play to the advantages of AnQiCMS's flexible content model.


Frequently Asked Questions (FAQ)

Q1: I created a custom field and filled it in the background, but I can't see any display on the document detail page. What went wrong?A1: First, check if you have added the code to display custom fields in the corresponding document detail page template, and make sure that the "Call field" name matches the one used in the template.nameThe parameter or variable name is exactly the same (case sensitive). Secondly, check if your template file has been loaded correctly by AnQiCMS.If the effect of the template file is not updated after modification, you may need to clear the system cache or refresh the browser cache.

Q2: How to display this image on the front end if my custom field is of image type?A2: When the custom field is of image type, its value is usually the URL of the image. You can use this field value as<img>a label, to use the value of this field assrcProperty. For example, if your image custom field's call field isproduct_photoyou can display it like this:<img src="{{ archive.product_photo }}" alt="图片描述" />.

Q3: My custom field is rich text or Markdown formatted, containing HTML tags or Markdown syntax, why did the original text show on the page instead of the tags being escaped?A3: The AnQiCMS template engine, for security reasons, defaults to escaping all output content to prevent XSS attacks. If your custom field content is already HTML or Markdown, you need to use|safeThe filter tells the template engine that this content is safe and does not need escaping. If the content is Markdown and you want it to be rendered as HTML, you need to add it before|safe.|renderfor example:{{ archive.rich_text_content|safe }}or{{ archive.markdown_content|render|safe }}.

Related articles

How to implement the display of previous and next document links in AnQiCMS templates?

When browsing website content, users often want to be able to navigate easily between related articles.In order to find more information or simply enjoy a smooth reading experience, the "Previous" and "Next" document links play a crucial role.They can not only effectively increase the user's stay time on the website, reduce the bounce rate, but also have a positive impact on the internal link structure of the website and the search engine optimization (SEO), helping search engines better understand the relevance of the website content.### Core Function Analysis: AnQiCMS

2025-11-08

How to use the AnQiCMS document list tag to display content for specific categories or recommended attributes?

In AnQi CMS, efficiently managing and displaying website content is the key to improving user experience and website operation effectiveness.Whether you want to display the latest articles of a specific category on the homepage or highlight products with the "recommended" attribute, the document list tag (`archiveList`) provided by AnQiCMS is the core tool to meet these needs.Its flexible parameter configuration allows us to accurately control content retrieval, transforming technical details into easily accessible operational strategies.

2025-11-08

How to display dynamic breadcrumb navigation in AnQiCMS and customize the home page name?

In website content management, breadcrumb navigation plays a crucial role.It not only helps visitors clearly understand their position on the website, provides a convenient path to return to the upper page, but also reflects the hierarchical structure of the website from the side, which is greatly beneficial to user experience and search engine optimization.AnQiCMS as a powerful content management system naturally provides a flexible way to manage and display this kind of navigation.

2025-11-08

How to integrate and display Markdown, mathematical formulas, and flowcharts correctly on the AnQiCMS page?

In AnQiCMS, adding Markdown, mathematical formulas, and flowcharts to content greatly enhances its expressiveness and readability, especially for technical documents, educational materials, or data analysis reports.AnQiCMS as an efficient content management system, provides flexible mechanisms to support these modern content display needs. To implement the correct display of Markdown, mathematical formulas, and flowcharts on the AnQiCMS page, it mainly involves enabling backend settings and the necessary introduction of frontend templates.Here are the detailed steps and some practical suggestions

2025-11-08

How to display the list of related documents in AnQiCMS, what is the logic?

How to effectively guide users to discover more interesting content in a content management system is the key to improving user experience and website depth.AnQiCMS handles the 'related document list' feature by providing a flexible and intelligent mechanism that allows us to easily display other articles or products closely related to the current content on the website. This not only helps to extend the user's stay on the website but also optimizes the search engine crawling efficiency through internal links.### AnQiCMS

2025-11-08

How to use AnQiCMS tags to display the document list under a specific Tag?

In AnQiCMS, tags are a powerful content organization method that helps us associate content with different categories and models more flexibly.Using labels appropriately can not only optimize the SEO performance of a website, but also significantly improve the user's experience in discovering content on the website.When we want to focus on displaying all relevant documents under a specific tag, AnQiCMS provides a set of intuitive and efficient template tags to meet this need.This article will introduce in detail how to use the built-in template tags of AnQiCMS

2025-11-08

How to display user comment lists and implement pagination in AnQiCMS?

In website content operation, user comments are an important part of enhancing interactivity and activity, and reasonable pagination can ensure that the comment list is both complete and loads smoothly.AnQiCMS (AnQiCMS) provides powerful and flexible template tags, allowing you to easily display and manage user comments on the front-end page, and implement pagination functionality for the comment list.

2025-11-08

How to retrieve and display custom form fields in AnQiCMS comment form?

When using AnQiCMS to manage website content, the online message function is undoubtedly an important means of interacting with visitors, collecting feedback, or gathering potential customer information.In addition to the basic name, contact information, and message content, we often need to collect more specific and personalized information, such as 'Your project budget', 'The type of service you are interested in', or 'The expected contact time'.AnQi CMS provides a flexible custom message field function, allowing us to easily meet these needs.How can I retrieve and elegantly display these custom form fields on the website front page?

2025-11-08