How to display custom fields defined in the AnQiCMS content model on the front end?

Calendar 👁️ 85

AnQiCMS's flexible content model is one of its core strengths, allowing us to define unique fields for different types of content according to actual business needs, thus freeing ourselves from the constraints of the fixed content structure of traditional CMS.After we create these custom fields, the next critical step is to elegantly display them on the website front end.

This article will detail how to define custom fields in the AnQiCMS backend and how to flexibly call and display this information in the frontend template, making your website content more personalized and practical.

One, define custom fields in the background content model

In AnQiCMS, all content publishing is based on the 'Content Model'.Whether it is an article, product, or other custom type, it corresponds to a specific content model.To display custom fields, we first need to add these fields in the corresponding content model.

  1. Enter content model managementLog in to the AnQiCMS backend, navigate to the 'Content Management' menu, and then click the 'Content Model' submenu.You will see the built-in 'article model' and 'product model', and you can also create new custom models.Select the model you want to add a custom field to, click the 'Edit' button to enter.

  2. Add custom fieldIn the model editing interface, you will find the 'Content Model Custom Field' area.This is where we define personalized fields. Click 'Add field' to appear a new form row, where you need to fill in the following information:

    • Parameter name (Name)This is the Chinese name displayed in the background management interface and editing page, which is convenient for you to understand and manage, such as 'article source', 'product model', 'release date', and so on.
    • Field call (FieldName)This is the unique identifier used to call this field in the front-end template, it must beEnglish lowercase lettersFor example, if the parameter name is "article source", you can set the called field tosourceIf the parameter name is "product model", it can be set tomodel_numberRemember this "call field", it is the key for front-end display.
    • Field Type (Type): Choose the field suitable for your content type, such as:
      • 单行文本: Suitable for brief text content, such as authors, short titles.
      • 数字: Only numbers are allowed.
      • 多行文本: Suitable for longer text descriptions.
      • 单项选择/多项选择/下拉选择Provide preset options for selection, with option content set in 'Default Value', one per line.
    • Is RequiredDetermine whether the field is required to be filled in when publishing content.
    • Default value (Content)To set an initial value for the field or provide options (for selection type fields).

    For example, suppose we want to add a "author email" field to the "article model" to facilitate direct contact with readers. We can set it up like this:

    • Parameter name: author email
    • Call field:author_email
    • Field Type: Single Line Text
    • Not Required
    • Default Value: Empty

    After adding the field, remember to click Save to make the changes take effect.

II. Display Custom Fields in the Front-end Template

After the custom field is defined and published, we can display them on the website front-end template.AnQiCMS uses a template engine syntax similar to Django, calling data through specific tags.Generally, the display of custom fields is concentrated on the document detail page template (such asarticle/detail.htmlorproduct/detail.html).

In the template file, you can choose two main ways to display custom fields: directly call specific fields or loop through all custom fields.

  1. Directly call a specific custom fieldIf you know which custom field to display and it is an independent value that does not require looping (such as text, numbers), you can use it directlyarchiveDetailTag to get its value.

    Suppose you define a "article source" field in the background, its "called field" issourceThen you can call and display it directly in the article detail page template:

    <p>文章来源:{% archiveDetail with name="source" %}</p>
    

    If your custom field name isauthor_emailYou can call it in the same way:

    <p>联系作者:<a href="mailto:{% archiveDetail with name="author_email" %}">{% archiveDetail with name="author_email" %}</a></p>
    

    This method is concise and clear, suitable for scenarios where precise control of the display position and format of a specific field is required.

  2. Loop through all custom fieldsIf you want to display all custom fields on the document detail page (or are unsure of which specific fields there are but want to display them all), you can usearchiveParamsLabel. This label will return an array or map containing all custom fields, which you can iterate over to dynamically display.

    archiveParamsThe tag will return an array sorted by order, each element containingName(parameter name, that is, the Chinese name set in the background) andValue(field value).

    <div>
        <h3>其他参数</h3>
        {% archiveParams params %}
            {% for item in params %}
                <p>{{item.Name}}:{{item.Value}}</p>
            {% endfor %}
        {% endarchiveParams %}
    </div>
    

    This code will traverse all the custom fields defined in the current document and display them one by one in the form of "parameter name: field value".

    If you want to access data in the form of a map to access it directly by key name, you can addsorted=falseparameters:

    {% archiveParams params with sorted=false %}
        <div>作者邮箱:{{params.author_email.Value}}</div>
    {% endarchiveParams %}
    

    But usually, using{% archiveDetail with name="调用字段" %}the way will be more intuitive and convenient.

  3. Handle special field types (such as image groups, multi-select)Some custom field types may require special handling to display better on the front end.

    • Image group fieldIf you define a custom field for uploading multiple images (for example, "Product Album", the field name isproduct_gallery)archiveDetailThe label will return an array of image URLs. You need to iterate over this array to display the images:

      <h3>产品相册</h3>
      <ul class="product-gallery">
          {% archiveDetail images_list with name="product_gallery" %}
          {% if images_list %}
              {% for img_url in images_list %}
                  <li><img src="{{ img_url }}" alt="产品图片" loading="lazy"></li>
              {% endfor %}
          {% endif %}
      </ul>
      
    • Multiple choice fieldIf your custom field is a 'Multiple Choice' (for example, 'Applicable Scenes', the field calledapplicable_scenes), the backend usually saves it as a comma-separated string (e.g., "home, office, travel"). When displaying on the front end, you can use|splitThe filter converts it into an array and then displays it in a loop:

      <p>适用场景:
          {% archiveDetail scene_str with name="applicable_scenes" %}
          {% if scene_str %}
              {% for scene in scene_str|split:"," %}
                  <span>{{ scene }}</span>{% if not forloop.Last %},{% endif %}
              {% endfor %}
          {% else %}
              <span>暂无</span>
          {% endif %}
      </p>
      
    • Rich text editor fieldIf your custom field uses a rich text editor (such as "Product Details Supplement", the field name is "extra_details),its content will include HTML tags. To ensure that these HTML contents are parsed correctly by the browser rather than displayed as plain text, you need to use|safefilter.

      <h3>详情补充</h3>
      <div>
          {% archiveDetail extra_content with name="extra_details" %}
          {{ extra_content|safe }}
      </div>
      

      This allows the image, layout, and other HTML formats defined in the field to be displayed as is.

Summary

By flexibly using AnQiCMS's content model and front-end template tags, you can easily display any custom field on the website to meet various personalized content display needs. Whether it is simple text, numbers, or complex image groups, multiple choice boxes, AnQiCMS

Related articles

How to customize the display template for articles, products, and single pages in AnQiCMS?

In AnQiCMS, customizing the display templates for articles, products, and single pages is a very flexible and powerful feature that allows you to create exclusive display styles for different types of content according to the unique needs of your website.By carefully designed templates, not only can the user experience be improved, but also the focus of the content can be better highlighted, achieving the unity of brand style.AnQiCMS uses a template engine syntax similar to Django, which means if you are familiar with this concise and intuitive syntax, you can quickly get started.

2025-11-08

How to use the `archiveParams` tag to retrieve and display the content of the custom parameter fields of the document?

In daily website operations, we often encounter the need that standardized content fields can no longer meet the diversified display of information.For example, a product detail page may need to display unique attributes such as "model", "material", "warranty period", etc., while a regular article may need additional notes such as "source of the article", "estimated reading time", etc.

2025-11-08

How to dynamically generate and display SEO titles, keywords, and descriptions for `tdk` tags on different pages?

In website operation, the title (Title), keywords (Keywords), and description (Description), known as TDK, are indispensable core elements of search engine optimization (SEO).They not only directly affect the display of the website on the search engine results page (SERP), but also determine whether users click to enter your website.

2025-11-08

What global website information and contact details can the `system` tag and `contact` tag retrieve and display?

In the daily operation of AnQiCMS, the global information and contact information of the website are highly concerned by users and frequently change.How to efficiently and uniformly manage and display this information is an important standard for measuring the flexibility of a content management system.AnQiCMS provides an extremely convenient solution for calling website content and contact information through its unique template tag system, especially the core tags `system` and `contact`.

2025-11-08

How does AnQiCMS implement the switch of multilingual content and correct display?

In order to meet the content operation needs of globalization, it is a key step to enable your website to support multi-language content switching and correct display, expanding the market and enhancing user experience.AnQiCMS (AnQiCMS) is a feature-rich content management system that provides an intuitive and powerful multilingual solution, helping you easily meet this challenge.Next, we will discuss in detail how to achieve this goal in AnQiCMS.

2025-11-08

How to dynamically display the 'recommended properties' (such as headlines, recommendations) of articles or products on a page?

When operating website content, we often need to make special recommendations for certain articles or products, such as 'headline', 'hot', or 'recommended', etc., in order to display them more prominently on the page and guide users' attention.AnQiCMS provides a very flexible "recommendation attribute" feature, allowing you to easily achieve this.Let's take a look together at how to set these properties in AnQiCMS and dynamically display them on your website.

2025-11-08

What thumbnail processing methods does AnQiCMS support, and how to set them to optimize the display effect?

In website operation, image content plays a crucial role, especially exquisite thumbnails can quickly attract users' attention, enhance the visual beauty of the page, and improve the click-through rate.AnQiCMS (AnQiCMS) offers flexible and diverse functions in image processing, especially for thumbnail generation and optimization, aiming to help websites achieve **display effects.We will delve into the thumbnail processing methods supported by AnQiCMS, as well as how to make your website images come to life through reasonable settings.### The core mechanism of AnQiCMS thumbnail processing First

2025-11-08

How to set a default thumbnail to automatically display when there is no image in the article?

In content operation, images play a crucial role.They can not only catch the visitor's eye, enhance reading interest, but also effectively convey information and enhance the brand image.However, when updating articles daily, we may occasionally forget to upload thumbnails, or some content is not suitable for pictures.This is when a blank page appears on the article list or detail page, which seems unprofessional and affects user experience.Fortunately, AnQiCMS (AnQiCMS) has considered this point and provided a very practical feature: setting a default thumbnail.With it, even if the article does not have a picture

2025-11-08