How to display additional field data in the front-end template after customizing the content model?

Calendar 👁️ 64

AnQiCMS with its flexible content model functionality has brought great convenience to us in managing various types of website content.Whether it is articles, products, activities, or any other content type that requires special fields, we can easily customize fields in the background to meet unique business needs.But when we eagerly created new fields in the background and filled them with data, a new problem also arose: How can we accurately display these newly added custom field data on the website's frontend page for visitors?

Don't worry, the AnQiCMS template system provides a very intuitive and powerful way to handle this issue.This article will guide you step by step on how to make your custom content model fields come alive in the frontend template.


Learn about the template mechanism of AnQiCMS

Before going deeper into the operation, we first need to have a basic understanding of AnQiCMS's template mechanism.AnQiCMS's template system uses the Iris framework built-in template engine written in Go language, which is very easy to get started with, similar to the Django template engine.

In AnQiCMS, template files are usually named with.htmlsuffix and stored in/templateIn the template folder. We use{{ 变量 }}to output data, through{% 逻辑标签 %}to implement conditional judgments, loops, and other complex logic. Understanding these basic elements is the foundation for successfully displaying custom field data.


Display specific custom field data on the content detail page

The most common requirement is to display the data of a specific field added to the content model on content detail pages such as article detail pages, product detail pages, and so on.For example, you may have added the 'Article Author' field to the 'Article Model' or the 'Product Color' field to the 'Product Model'.

We need to use to display these fieldsarchiveDetailLabel. This label is usually used to get the details of the current document, and it also perfectly supports getting our custom fields.

Operation steps:

  1. Find the corresponding template file:If you are modifying the article detail page, the corresponding template file is usuallyarticle/detail.htmlor if the default folder organization mode is usedarticle_detail.htmlIf a flattened file organization mode is used). The product detail page might beproduct/detail.htmlorproduct_detail.html.

  2. UsearchiveDetailTags:Find the location in the template file where you want to display a custom field, and then use the following syntax:

    {# 假设您在后台自定义了一个名为“文章作者”,其“调用字段”为“author”的字段 #}
    <div>
        文章作者:{% archiveDetail with name="author" %}
    </div>
    
    {# 或者,您可以先定义一个变量来存储字段值,再输出,这样更灵活 #}
    {% archiveDetail articleAuthor with name="author" %}
    <div>
        文章作者:{{ articleAuthor }}
    </div>
    

    What is most critical isname="author"This part,authorMust be consistent with the "call field" you filled in for this custom field in the "Content Model" settings in the background (case-sensitive).

    Similarly, if you add a "product color" field to the "product model", its "called field" iscolorThen you can display it like this in the product detail page template:

    {# 产品颜色自定义字段,调用字段为“color” #}
    <div>
        产品颜色:{% archiveDetail with name="color" %}
    </div>
    

    For single-page (pageDetail) and category (categoryDetail) usage is quite similar, just need to usearchiveDetailReplacepageDetailorcategoryDetail, and ensurenamethe parameter corresponds to the custom fields under the model.


Flexible traversal and display of all custom field data

Sometimes, we may not want to list each custom field individually, but rather hope to automatically iterate and display all defined custom parameters and their values in a region (such as a product parameter list). In this scenario,archiveParamsthe tag comes into play.

archiveParamsThe tag returns an array object containing all custom field names and values, we can traverse and display throughfora loop.

Operation steps:

  1. Introduce in the templatearchiveParamsTags:

    {# 假设这是产品详情页,需要在一个区域展示所有自定义参数 #}
    <div class="product-parameters">
        <h3>产品详细参数</h3>
        {% archiveParams params %}
            {% for item in params %}
                <div class="parameter-item">
                    <span class="parameter-name">{{ item.Name }}:</span>
                    <span class="parameter-value">{{ item.Value }}</span>
                </div>
            {% endfor %}
        {% endarchiveParams %}
    </div>
    

    In this example,paramsIt is the variable name defined, it contains all the custom parameters of the document. In the loop,item.Namewill output the Chinese name of the parameter (i.e., the "parameter name" filled in the background),item.ValueIt will output the value corresponding to the parameter.

    archiveParamsBy default, it will return an sorted array. If there are special cases where you need to access directly through the 'call field', you can usesorted=falseThe parameter, it will return an object in the form of a key-value pair. For example, if you have a field calledmaterialThe custom field: “`twig {% archiveParams customFields with sorted=false %}

    产品材质:{{ customFields.material.Value }}
    

    {% endarchiveParams %}

Related articles

How to implement the function of displaying and switching content in multiple languages?

Make your website go global: Anqi CMS multilingual content strategy and implementation In today's globalized digital age, many businesses and content creators hope that their websites can reach a wider audience.This means providing content display and switching functions in multiple languages to meet the reading habits of users in different countries and regions.AnQiCMS (AnQiCMS) is an efficient content management system that fully considers this requirement, providing a flexible solution to help you easily implement the multilingual function of the website.In AnQi CMS, implement multi-language display and switching of content

2025-11-09

How to retrieve and display the SEO title and description of the current document in the template?

In website operation, Search Engine Optimization (SEO) is a key element to enhance website visibility.And the page title (Title) and description (Description) as the first information seen by search engines and users browsing, its importance is self-evident.AnQiCMS (AnQiCMS) knows this and therefore provides a flexible and powerful mechanism to retrieve and display these SEO elements in the template.### AnQi CMS's TDK (Title, Description,

2025-11-09

How to set and optimize the static URL structure of a website to enhance the display effect in search engines?

The importance of website operation and URL structure is self-evident.A clear and meaningful URL not only helps users better understand the page content, but is also a key factor in search engine optimization (SEO).Especially for content management systems, properly setting up the pseudo-static URL structure can significantly improve the display effect and user experience of the website in search engines.AnQiCMS as a content management system that focuses on SEO optimization, provides strong and flexible support in this aspect.It not only built-in a variety of commonly used pseudo-static rules

2025-11-09

What device adaptation modes does AnQiCMS support to optimize content display?

With the popularization of mobile internet, the types of devices used by users to access websites are becoming increasingly diverse, ranging from large-screen PC monitors to compact smartphones. The display effect of website content is directly related to user experience and the effective transmission of information.AnQiCMS is well-versed in this field, providing a variety of device adaptation modes to help users flexibly optimize content display and ensure that the website presents a**status**on any device.The device adaptation strategy of AnQi CMS is mainly divided into three types, each mode has its unique implementation method and applicable scenario

2025-11-09

How to enable Markdown rendering and correctly display mathematical formulas and flowcharts in AnQiCMS?

In AnQiCMS, if you want to make your content more expressive, especially when it comes to displaying complex mathematical formulas or clear flowcharts, it is a very effective solution to flexibly use the Markdown editor.The new version of AnQiCMS has provided good support for this.Next, we will explore together how to enable these features in AnQiCMS, making your website content come alive.

2025-11-09

How to embed a comment list on the page and control its pagination display?

In website operation, user interaction is the key to enhancing site activity and content value.AnQiCMS provides a set of intuitive and powerful features that help us easily embed comment functions in pages and flexibly control the display of comment lists, especially its pagination management, which is crucial for pages with a large number of user comments. ### Enable comment functionality to bring content to life Firstly, we need to ensure that the comment functionality is enabled on the backend so that users can post comments.Once the comment feature is activated

2025-11-09

How to loop through and display all subcategories under a specified category in a template?

How to elegantly display all subcategories under a specified category in Anqi CMS template?For a content-rich website, a clear classification structure is the key to improving user experience and search engine friendliness.AnQiCMS (AnQiCMS) takes advantage of its flexible template engine and powerful tag system, allowing you to easily traverse and display all subcategories under a specified category on the website front end, whether it is a direct subcategory or a multi-level nested subcategory, you can handle it with ease.Today, let's discuss how to implement this feature in Anqi CMS templates.

2025-11-09

How to display a second-level dropdown menu in the navigation menu and associate different content?

AnQi CMS provides a直观and powerful navigation menu management system, allowing you to easily build a clear, user-friendly navigation structure for your website, including multi-level dropdown menus.This not only improves the user experience of the website, but also helps search engines better understand the hierarchy of your website content, thus optimizing SEO performance. ### Understanding the navigation system of Anqi CMS In Anqi CMS, the settings and management of the navigation menu are concentrated in the "Website Navigation Settings" function in the background.This is the core area where you build your website menu

2025-11-09