How to display custom model field information in the document list?

Calendar 👁️ 69

In AnQi CMS, the flexibility of the content model is one of its outstanding advantages.Many times, we not only need to display rich content on the document detail page, but also hope to see key custom information at a glance on the document list page, such as product models, article authors, property prices, and vehicle mileage, etc.This information is often an important basis for users to quickly screen and understand the content.This article will thoroughly explain how to cleverly display these customized model field information in the document list of AnQi CMS.

Flexible customization: Understand the Anqi CMS content model

Our Anqi CMS allows us to create a variety of content models based on actual business needs.For example, in addition to the built-in articles and product models of the system, we can also create models such as "newsEach model can have its own unique set of fields, which together define the structure and content of the model.

Custom fields are the soul of the content model.They can be simple text input boxes, as well as numbers, multi-line text, single selection, multiple selection, and even file upload, among other types.By these custom fields, we can add more specific and personalized attributes to the content, thereby better managing and displaying our website content.

Step 1: Define custom fields in the background

To make custom fields display in the document list, first we need to make sure that these fields are defined in the content model of the Anqi CMS backend.

  1. Enter content model management: Log in to the Anqi CMS backend, navigate to "Content Management" -> "Content Model".
  2. Select or create a model:Select the model you want to add a custom field to (for example, 'Article Model' or 'Product Model'), or create a new content model.
  3. Add custom fieldOn the model editing page, find the "Content Model Custom Field" area. Click "Add Field" to add the required custom information to your model.
    • Parameter NameThis is the field displayed in the background management interface, usually in Chinese, easy to understand (such as 'Product Model', 'Article Author').
    • Field invocationThis is the unique identifier used in the template to call this field, it must be alphabetic.This is the key we use in the front-end template (for example, "model_number", "author_name").
    • Field type: Choose the data type you want to store, such as 'single-line text', 'number', 'multi-line text', etc.
    • Mandatory?: Set according to requirements.
    • Default valueA default value can be preset, which will be automatically applied if the user does not fill in the content at the time of publication.
  4. Save modelAfter adding fields, be sure to save the changes to the content model.

After completing this step, when you publish the document under the corresponding model, you will see these newly added custom fields and can fill in their content.

Step two: Modify the template, call the custom field on the list page

In Anqi CMS, the presentation of the website page is determined by the template file. To display custom fields in the document list, we need to modify the corresponding list page template file.

The template of AnQi CMS follows a syntax similar to the Django template engine, variables are enclosed in double curly braces{{变量}}Logic control uses{% 标签 %}. Template files are usually stored in/templateIn a directory, and organized according to a certain directory structure (for example{模型table}/list.htmlfor the list page).

We will mainly usearchiveListtags to get the document list, and combine them in a loop.archiveParamsLabel to retrieve custom fields for each document.

  1. Locate the list page template file.:

    • Assuming you want to display custom fields on the article list page, you need to find the corresponding article list template, usuallytemplate/你的模板名称/article/list.htmlortemplate/你的模板名称/archive/list.html.
    • If you are not sure which file it is, you can refer to the naming conventions of the 'Document List Page' in the 'Template Creation Directory and Template' document.
  2. Get document list: In the list template, there is usually aarchiveListtag to loop through documents:

    
    {% archiveList archives with type="page" limit="10" %}
        {% for item in archives %}
            {# 这里是每个文档的显示区域 #}
            <a href="{{item.Link}}">
                <h5>{{item.Title}}</h5>
                <div>{{item.Description}}</div>
                {# ... 其他内置字段 ... #}
            </a>
        {% empty %}
            <p>目前没有文档。</p>
        {% endfor %}
    {% endarchiveList %}
    
    itemrepresenting each document object in the loop, we can get the built-in fields of the document throughitem.Title/item.Linkand so on.

  3. Call custom model field: Custom model field is not directly included initemthe object. We need toforuse the tag inside the loop for each document toarchiveParamsget its custom field.archiveParamsThe tag needs to pass the current document'sIDto get the corresponding field information.

    {% archiveList archives with type="page" limit="10" %}
        {% for item in archives %}
            <div class="document-item">
                <a href="{{item.Link}}">
                    <h3>{{item.Title}}</h3>
                    <p>{{item.Description}}</p>
                    {# 显示自定义字段区域 #}
                    <div class="custom-fields">
                        {% archiveParams params with id=item.Id %}
                            {% for field in params %}
                                {# field.Name 是后台设置的“参数名”(中文) #}
                                {# field.Value 是该字段的具体内容 #}
                                <p><strong>{{field.Name}}:</strong> {{field.Value}}</p>
                            {% endfor %}
                        {% endarchiveParams %}
                    </div>
                </a>
            </div>
        {% empty %}
            <p>目前没有文档。</p>
        {% endfor %}
    {% endarchiveList %}
    

    In the code above, we go through{% archiveParams params with id=item.Id %}to get the currentitem(document) all custom fields, and store them inparamsIn the variable. Then, we use it againforLoop throughparamsVariable, you can display the name and value of each custom field.

  4. Display specific custom fields as neededIf you are only concerned with a specific custom field and know its 'reference field' name (such as the one we defined before)author_nameyou can also directly pass througharchiveDetailtags:

    {% archiveList archives with type="page" limit="10" %}
        {% for item in archives %}
            <div class="document-item">
                <a href="{{item.Link}}">
                    <h3>{{item.Title}}</h3>
                    <p>{{item.Description}}</p>
                    {# 显示特定的自定义字段,例如“文章作者” #}
                    <p>
                        <strong>作者:</strong> {% archiveDetail with name="author_name" id=item.Id %}
                    </p>
                </a>
            </div>
        {% empty %}
            <p>目前没有文档。</p>
        {% endfor %}
    {% endarchiveList %}
    

    This method is more concise when displaying a small and fixed number of custom fields.

Points to note

  • Clear cache: After modifying the template file, you may need to log in to the Anqi CMS backend, click the 'Update Cache' button, so that the modification takes effect.
  • Field type processing:
    • Multi-line text (rich text)If the custom field is a multi-line text or rich text editor type, its content may contain HTML tags. When outputting, it is necessary to use|safeA filter to ensure that HTML is parsed correctly and not displayed as plain text, for example{{field.Value|safe}}.
    • Image type: If the custom field is an image upload type, itsfield.ValueThis stores the image URL. When displaying, you need to wrap it in<img>tags:<img src="{{field.Value}}" alt="{{item.Title}}">. If you need to display a thumbnail, you can usethumbFilter:<img src="{{field.Value|thumb}}" alt="{{item.Title}}">.
    • multiple selection/dropdown selectionThese fields' values may be an array or a comma-separated string. Depending on the actual storage format, you may need to further process it (for example, usingsplitThe filter splits the string into an array and then loops through it to display).
  • Accuracy of field name call: Always use the field name set in the background (in English letters), not the parameter name (in Chinese), and pay attention to the case.

By following these steps and注意事项, you can flexibly display various custom model field information in the Anqi CMS document list, thereby greatly improving the management efficiency and user experience of website content.


Frequently Asked Questions (FAQ)

1. I added a custom field in the background and modified the list template, but the front-end page did not display. What went wrong?Make sure you have clicked 'Save' after modifying the content model in the background, and confirm that you are using the correct 'Field Name' in the template (not 'Parameter Name').At the same time, the most important step is to log in to the Anqi CMS backend, click the 'Update Cache' button at the bottom of the left navigation bar, clear the system cache, so that template modifications can take effect in a timely manner.

2. Why is the list page displaying a picture link instead of the picture itself when my custom field is of image type?Image type custom field, its value is usually the URL of the image. In the template, you need to put this URL in the<img>label'ssrcattribute to display the image. For example:<img src="{{field.Value}}" alt="{{item.Title}}">If you want to display a thumbnail, you can also use{{field.Value|thumb}}filter.

3. How do I display multiple selected values for my custom field on the list page?The values of multi-select fields are usually stored in a string separated by commas or other delimiters. You can use them in a template.splitThe filter can split them into an array, then throughforLoop through and display each option. For example:{% for option in field.Value|split:"," %} <span>{{option}}</span> {% endfor %}The specific separator needs to be determined according to the default format set in your backend.

Related articles

How to filter and display content under specific models or categories on the document list page?

When managing website content, we often need to display specific types or themes of content on different list pages, such as article lists, product showcase pages, or detailed summaries of custom models.This not only concerns whether users can find the information they need efficiently, but also directly affects the overall layout and user experience of the website.Anqi CMS with its flexible content model and efficient system architecture provides us with powerful tools to accurately filter and personalize content display.### The Core of Content Organization: Models and Classification In AnQi CMS

2025-11-08

How to customize the website navigation menu to display multi-level content links?

During the process of building and operating a website, the navigation menu plays a crucial role.It is not only a guide for users to explore the content of the website, but also the key for search engines to understand the structure of the website.AnQiCMS (AnQiCMS) fully understands this point, therefore it provides a flexible and powerful navigation menu customization feature, allowing us to easily implement the display of multi-level content links, thereby optimizing user experience and enhancing the overall efficiency of the website.Next, we will together learn how to customize and manage the website navigation menu in Anqi CMS, and make it able to flexibly display multi-level content links.##

2025-11-08

How to set independent TDK (title, description, keywords) for the homepage of a website to optimize search results display?

How to make your website stand out among a vast amount of information and gain more exposure in website operation?In this case, Search Engine Optimization (SEO) plays a vital role, and the title (Title), description (Description), and keywords (Keywords), which we commonly refer to as TDK, are the cornerstone of SEO strategy.For users of AnQiCMS, setting up independent homepage TDK is not only simple and efficient, but also a key step in optimizing website search performance.Why is the TDK setting on the homepage crucial

2025-11-08

How to dynamically display contact information in website templates?

When operating a website, we often need to display the company's contact information, such as phone, email, address, and even social media links.The traditional way might be to hardcode this information directly in the template, but this means that every time the contact information changes, you need to modify the code, which is麻烦 and easy to make mistakes.AnQiCMS (AnQiCMS) provides a flexible and efficient solution that allows you to easily display and manage these contact methods in website templates.This means that once the contact information changes, you only need to update it once in the background

2025-11-08

How to manage and display single-page content on the website, such as 'About Us'?

Manage and display single-page content in Anqi CMS: from creation to optimization Most websites cannot do without static pages such as "About Us", "Contact Information", and "Privacy Policy".These pages, although relatively fixed in content, are important windows for users to understand the website and establish trust, and are also key factors for search engines to evaluate the professionalism of the website.AnQi CMS understands the importance of these pages and provides a set of intuitive and powerful tools that allow you to easily manage and beautifully display this single-page content.

2025-11-08

How to classify and manage uploaded image resources, and optimize the front-end display?

In the process of using AnQiCMS to manage website content, the management and optimization of image resources is an essential element for improving website user experience and SEO performance.A well-organized image library not only makes daily operations more efficient, but also ensures that website content is presented in **status across different devices and network environments. ### Picture Resource Classification Management: Say goodbye to chaos and have everything in order AnQi CMS provides us with an intuitive picture resource management interface, making a large number of pictures no longer a problem of piles.To start organizing, we just need to go to the back end

2025-11-08

How to integrate Markdown editor into a website and correctly display mathematical formulas and flowcharts?

In today's increasingly rich digital content, websites are no longer just a pile of text and images.For users who need to display technical documents, academic papers, data analysis reports, and even complex business processes, how to efficiently and beautifully present mathematical formulas and flowcharts has become a key factor in enhancing the professionalism and user experience of the content.AnQi CMS is well-versed in this, providing powerful Markdown editor integration capabilities, with simple frontend configuration, allowing your website to easily support the display of these advanced content.

2025-11-08

How to precisely control which document IDs, titles, and links are displayed on the article detail page?

In website operation, the article detail page is the core touch point for users to obtain information, and its way of information presentation directly affects user experience and the transmission of content value.AnQiCMS as a flexible content management system provides powerful and fine-grained control capabilities, allowing you to accurately display the required document ID, title, link, and other information on the article detail page. To precisely control the content of the article detail page, we mainly rely on the template tag system of AnQiCMS.The core lies in the `archiveDetail` tag

2025-11-08