How to display custom fields (such as author, source) of AnQi CMS documents on the front-end page?

Calendar 👁️ 85

When managing content in AnQi CMS, we often encounter situations where we need to add more personalized data to articles, products, or pages, such as the author of the article, the source of the content, or specific parameters of the product, or specific attributes of the event page, etc.This additional customization information is referred to as 'custom fields'.The powerful content model function of AnQi CMS makes the creation and management of custom fields very convenient, and more importantly, how to accurately and beautifully present these meticulously entered custom fields on the front page of the website is a concern for every operator and developer.

This article will take you deep into how Anqi CMS presents these custom document fields cleverly on your website page.

Backend configuration: Create custom fields

You need to define the custom fields in the backend first in order to display them on the front end.AnQi CMS provides a flexible content model, allowing you to add dedicated fields for different content types (such as articles, products) based on your business needs.

After logging into the backend, we can find the "Content Model" option under the "Content Management" menu.Here, you can select an existing model (such as "article model"), or create a new content model.After entering the model editing page, in the "Content Model Custom Fields" area, you can start adding custom fields.

When adding fields, there are several key pieces of information that need to be filled in:

  • Parameter NameThis is the field name in the background management interface and template for you to identify, such as "article author", "content source".
  • Field invocationThis is the unique English identifier that is actually referenced in the database and template, for example, you can set the call field for "article author" toauthorSet the calling field for "Content Source" tosourceThe name of this "calling field" is the key we use to retrieve data in the front-end template.
  • Field type: Anqi CMS supports various field types, such as single-line text, numbers, multi-line text, single choice, multiple choice, and dropdown selection, etc.Choose the appropriate field type, which ensures the accuracy of the data you enter and also affects the frontend display.
  • Mandatory?According to the importance of the field, you can set it as required.
  • Default valueIf the field often has a fixed value, you can set a default value so that when the content is published, if it is not filled in manually, the default value will be applied automatically.

For example, if we want to add an "author" field to an article, we can add a new field in the article model, the parameter name is "article author", and the field name is calledauthorThe field type should be selected as 'Single line text'. Similarly, a 'Content Source' field can be added, with the field name beingsource. When you are editing specific article content, these custom fields will appear in the "Other Parameters" area, where you can fill in the corresponding information.

Front-end display: Let custom information leap onto the screen

After the custom field is configured and filled in the background, the next step is to figure out how to display them in the front-end HTML template through the AnQi CMS template engine tags. The AnQi CMS template engine syntax is similar to Django, and variables are enclosed in double curly braces{{变量}}Logical tags are represented by single curly braces and percent signs{% 标签 %}.

There are usually two main ways to display custom fields in front-end templates:

Method one: Directly call the specific custom field

If you know the name of a custom field's "call field" (for exampleauthororsource), and you want to display its value directly on the article detail page or other specific locations, you can usearchiveDetailTag to accurately obtain.

In the article detail page (for example{模型table}/detail.htmlYou can call it like this in the template:

<p>作者:{% archiveDetail with name="author" %}</p>
<p>来源:{% archiveDetail with name="source" %}</p>

here,name="author"This is the field called by our backend. Written like this, the template engine will automatically identify the ID of the current article and retrieve the correspondingauthorandsourcefield value to display.

You can also assign the field value to a variable first, and then use:

{% archiveDetail articleAuthor with name="author" %}
<p>作者:{{ articleAuthor }}</p>

This method is especially suitable for displaying specific information at a fixed position on the page.

Method two: Loop through all custom fields

Sometimes, you may want to dynamically display all custom fields and their values, or be unsure about which custom fields there are, and need to render based on actual data. At this time,archiveParamsThe tag comes into play. It can retrieve all the custom parameters set for the current document (article, product, etc.) and allows you to display them one by one through a loop.

archiveParamsTags usually return custom fields as an array object, each containing theName(parameter name, that is, the display name) andValue(field value).

In the article detail page, you can dynamically display all custom fields in this way:

<h3>更多文章信息</h3>
<div>
    {% archiveParams params with sorted=true %}
        {% for item in params %}
            <div>
                <span>{{ item.Name }}:</span>
                <span>{{ item.Value }}</span>
            </div>
        {% endfor %}
    {% endarchiveParams %}
</div>

This code will iterate over all the custom fields of the current article and list them in the form of "parameter name: field value." For example, if the article has two custom fields, "author" and "source", it will display:

Author: Zhang San Source: Some News Website

If you want to control the display more finely, for example, to skip certain fields, you can add conditional judgments in the loop:

{% archiveParams params %}
    {% for item in params %}
        {% if item.Name != '文章作者' %} {# 假设你不想显示“文章作者”这个字段 #}
            <div>
                <span>{{ item.Name }}:</span>
                <span>{{ item.Value }}</span>
            </div>
        {% endif %}
    {% endfor %}
{% endarchiveParams %}

Handling of special field types

For different types of custom fields, the data format displayed on the front end may vary, but the core principle remains the same:

  • Single-line text, numbers, multi-line text:item.ValueThey will be their values directly. If multiline text may contain HTML, remember to use|safea filter to ensure that the HTML content is rendered correctly, for example{{ item.Value|safe }}.
  • image groupIf you define a custom field of image group type (such as calling field asarcimages), itsValueIt will be an array of image URLs. You need to traverse it like a normal array to display each image:
    
    {% archiveDetail customImages with name="arcimages" %}
        {% for imgUrl in customImages %}
            <img src="{{ imgUrl }}" alt="" />
        {% endfor %}
    {% endarchiveDetail %}
    
  • Single choice, multiple choice, dropdown choice:item.ValueIt will be the text value selected by the user. If multiple selections are made,item.ValueIt will be a string or an array containing multiple options, depending on the backend storage method, which may require further processing (such as using|splitfilter splitting).

Some practical tips:

  1. Keep the field name consistentWhen setting custom fields in the background, the name of the 'field name' must be kept in English

Related articles

How to use the `tagList` tag to display the associated tag list on the article detail page?

In content operation, tags (Tags) are a very practical tool that can help us organize content more flexibly, making it convenient for readers to quickly find related topics of interest.Imagine that after a user reads an excellent article, if they can immediately see other popular topics or keywords related to that article, it will undoubtedly greatly enhance their browsing experience and encourage them to explore other content on the website.In Anqi CMS, implementing this feature is very intuitive and simple, we mainly rely on the powerful `tagList` tag to complete it.

2025-11-09

How to display the category information of the articles on the front page of AnQi CMS, including the category name and link?

In Anqi CMS, the display of article category information on the front page is a key link in content organization and user navigation.Whether it is to help users understand the context of the article or to optimize the website's SEO structure, accurate and accessible category names and links play an important role.AnQi CMS with its flexible template engine makes this task intuitive and efficient.Understanding Anqi CMS's Classification System Before delving into the display methods, we first need to know that Anqi CMS's content management system attaches great importance to the concept of 'classification'.Each document (whether it is an article

2025-11-09

How to display the publication time of articles in Anqi CMS and customize the date and time format?

When operating website content, the publication time of the article is an indispensable element.It not only helps visitors quickly understand the "freshness" of the content, but also has a positive impact on search engine optimization (SEO), as it conveys the signal that the website content is continuously updated.AnQiCMS provides great flexibility in content management, whether it is to obtain or customize the display time of published articles, it is very convenient.Next, we will explore how to flexibly display the publication time of articles in Anqi CMS

2025-11-09

How to display the cover image (Logo) and thumbnail (Thumb) of an AnQi CMS article?

In content operation, the cover image (Logo) and thumbnail (Thumb) of the article play a crucial role. They not only attract readers' attention and increase click-through rates, but are also an indispensable part of search engine optimization (SEO).AnQiCMS (AnQiCMS) provides users with a flexible and convenient way to manage and display these visual elements.This article will discuss in detail how to configure and call the cover image and thumbnail of the article in AnQiCMS.## One, Configuration and generation of cover image and thumbnail In AnQiCMS

2025-11-09

How to build and display a multi-level product category navigation in AnQi CMS?

AnQi CMS is a powerful content management system that provides users with the ability to flexibly build and display multi-level product classification navigation.This not only helps website visitors easily find the products they need, but also effectively improves the website's SEO performance and optimizes the user experience.Let's explore together how to achieve this goal in Anqi CMS. ### Core Basics: Understanding the Classification System of AnQi CMS In AnQi CMS, the construction of multi-level product classification navigation is inseparable from its core "content model" and "document classification" functions. First

2025-11-09

How to get and display the custom Banner image group of the `categoryDetail` tag?

In website operation, configuring unique visual elements for different category pages, such as customized banner image groups, is crucial for enhancing user experience and strengthening brand recognition.AnQiCMS (AnQiCMS) leverages its flexible content management capabilities, allowing users to easily set up exclusive Banners for each category and provides intuitive template tags for conveniently displaying these contents on the frontend page.We all know that when users browse a website, the category page is a key entry point for them to explore content.

2025-11-09

How to effectively display the description (Description) and content (Content) on the front page?

In AnQi CMS, the description (Description) and content (Content) are key elements for website content organization and search engine optimization (SEO).Effectively display this information on the front page, not only providing visitors with clear navigation and in-depth information, but also helping search engines better understand the theme of the page, thereby improving the visibility of the website.Let's explore how to flexibly display the description and content of categories in the Anqi CMS front-end template together.

2025-11-09

How does the `pageList` tag in Anqi CMS display all single page lists and exclude specific pages?

AnQi CMS is a flexible and efficient content management system that provides strong support for our website operations, whether it is publishing articles, managing products, or creating various single-page applications, it shows great proficiency.Today, let's talk about a very practical skill when using Anqi CMS to manage single-page applications: how to display all single pages through the `pageList` tag while also accurately excluding specific pages that we do not want to display.In daily website operations, we often create some single-page pages such as "About Us", "Contact Information", "Privacy Policy" and so on

2025-11-09