How to display the custom parameter fields of AnqiCMS documents on the front page, such as authors, sources, and so on?

Calendar 👁️ 65

In website operation, the flexibility of the Content Management System (CMS) is crucial.Our AnQi CMS, with its powerful customizability, allows us to add various custom parameter fields to content (such as articles, products, etc.) to meet diverse display needs.These custom fields, such as the 'author', 'source', 'model', 'color' of products, etc., can greatly enrich the dimensions and practicality of content.

How can we elegantly present these personalized custom parameters to visitors on the front page of the website after we add them in the background?This article will guide you through the operation in detail.

Why do we need custom parameters?

The Anqi CMS provides the core function of "flexible content model", which is not limited to traditional fixed fields such as article title, content, and introduction.Under many circumstances, we need to define unique properties for specific types of content.For example, a news website may need to add "reporter name" and "news source" to each article;An e-commerce website may need to add "brand", "target audience", or "warranty period" for each product, etc.These custom parameters can make your content more structured, more in line with business logic, and easier to manage and search.They not only improved the professionalism of the content, but also provided users with richer and more accurate information.

Backstage settings: Create your custom parameters

Before displaying custom parameters on the front-end, we first need to ensure that these parameters have been correctly created and filled in the background of AnQi CMS.

  1. Enter content model management:Log in to the AnQi CMS backend, navigate to the 'Content Management' section, and find the 'Content Model' option.
  2. Select or create a content model:You can add custom fields to existing 'article model' or 'product model', or create a new content model as needed.
  3. Add custom field:In the content model editing page you choose or create, you will see the "Content Model Custom Field" area. Click "Add field", and you need to fill in the following key information:
    • Parameter name:This is the Chinese name displayed to the backend administrator, for example, 'Article Author', 'Content Source'.
    • Call field:This is the actual English identifier used in the template, which is very important. For example, 'author', 'source'. It is recommended to use meaningful lowercase letters.
    • Field type:Choose the actual data type of the parameter, for example, 'Single-line text' (for author name, source URL), 'Number' (for product inventory), 'Multi-line text' (for more detailed descriptions), 'Single choice' or 'Multiple choice' (for preset options).
    • Mandatory?:Check as needed, if this field is required, check this option.
    • Default:You can set a default value for this field if it is commonly used.
  4. Save the model and fill in the content:After setting up custom fields, save the content model. Next, when adding or editing documents under "Content Management", you will see these newly added custom fields in the "Other Parameters" area, and you can fill in the corresponding values for each document.

Make sure the name of the 'invoked field' is unique and easy to remember, as this will be our basis for referencing them in the front-end template.

Front-end display: Call custom parameters in the template.

The Anqi CMS template engine supports syntax similar to Django, using{% tag %}to perform logical control, using{{变量}}to output content. To display custom document parameters, we mainly usearchiveDetailandarchiveParamsthese two template tags.

1. Directly call a specific custom field (archiveDetail)

If you only need to display a specific custom parameter on the page (such as "author" or "source"), you can usearchiveDetaillabel and specifynameThe attribute is the name of your 'call field'.

Assuming you created a call field namedauthor(parameter name 'author') and another call field namedsource(Parameter named "Content Source") custom parameter. In the document detail page template (usually{模型table}/detail.html), you can call them like this:

<div class="article-meta">
    <span>作者:{% archiveDetail with name="author" %}</span>
    <span>来源:{% archiveDetail with name="source" %}</span>
    {# 也可以将值赋值给一个变量,再使用 #}
    {% archiveDetail articleAuthor with name="author" %}
    {% if articleAuthor %}
        <span>发布者:{{ articleAuthor }}</span>
    {% endif %}
</div>

Description:

  • {% archiveDetail with name="author" %}It will directly output the current document inauthorfield value.
  • IfauthorThe field may be empty, you can first assign it to a variable (such asarticleAuthor), and then use{% if articleAuthor %}to make a judgment to avoid displaying an empty label.
  • archiveDetailThe label defaults to retrieving information about the current page document. If you need to retrieve documents with other specified IDs or aliases, you can addid="文档ID"ortoken="文档URL别名"Parameter.

2. Loop through all custom fields (archiveParams)

Sometimes you may need to display all the custom parameters of the document, or you may wish to display them in a list.archiveParamsThe tag allows you to get all the custom parameters of the document and display them by looping in the template.

<div class="custom-parameters">
    <h3>文档额外参数</h3>
    {% archiveParams params %}
        {% for item in params %}
            <div class="param-item">
                <span class="param-name">{{ item.Name }}:</span>
                <span class="param-value">{{ item.Value }}</span>
            </div>
        {% endfor %}
    {% endarchiveParams %}
</div>

Description:

  • {% archiveParams params %}It will assign all the custom parameters of the current document as an array object.paramsVariable.

  • By{% for item in params %}You can iterate over this array, eachitemContainsName(parameter name, such as "article author") andValue(parameter value, such as "Zhang San") properties.

  • Handle special field types:If your custom parameter type is 'Multiple choice' or 'Group image' or other fields that require special handling,item.ValueIt may return an array or a JSON string. You need to handle it according to the actual situation. For example, ifarcimagesis a grouping field, you can traverse it like this:

    {% archiveDetail arcimages with name="arcimages" %}
    {% if arcimages %}
        <ul class="product-gallery">
            {% for imgUrl in arcimages %}
                <li><img src="{{ imgUrl }}" alt="产品图片"></li>
            {% endfor %}
        </ul>
    {% endif %}
    
  • Filter unnecessary fields:You can also add conditional judgments in the loop to exclude some internal custom parameters that you do not want to display on the front end:

    {% archiveParams params %}
        {% for item in params %}
            {% if item.Name != '内部标记' and item.Name != '隐藏参数' %}
                <div class="param-item">
                    <span class="param-name">{{ item.Name }}:</span>
                    <span class="param-value">{{ item.Value }}</span>
                </div>
            {% endif %}
        {% endfor %}
    {% endarchiveParams %}
    

Important reminder:

  • Security:If the custom parameter may contain HTML code (for example, if a rich text editor is used), in order to avoid XSS attacks and ensure correct rendering, it is imperative to use|safea filter such as{{ item.Value|safe }}The output content is escaped by default in AnQi CMS,|safeThis kind of escaping can be canceled.
  • Handling of default values and empty values:When setting custom parameters in the background, you can set a default value for them. If the parameter is empty when the front-end calls it, no content will be displayed. You can access{% if 变量名 %}Make a judgment to control the display logic.
  • Style:After displaying the custom parameters on the front end, you can use CSS to.article-meta/

Related articles

How to display the AnqiCMS related document list on the front page to increase content relevance and user stay time?

In content operation, we all hope that users can stay longer on the website and browse more content.An精心 crafted article is indeed important, but how to connect it with other relevant content to form a content matrix is the key to improving user experience and reducing bounce rate.Imagine, after a user finishes reading an article about 'AnQi CMS Core Features', if the page below automatically recommends 'How to Build an E-commerce Site with AnQi CMS' or 'AnQi CMS Template Creation Tutorial', wouldn't it be more attractive for them to continue exploring?

2025-11-09

How to display the 'Previous' and 'Next' documents of the current document on the front page to enhance the user's browsing experience?

In AnQiCMS (AnQiCMS), adding "Previous" and "Next" navigation links to the front-end document pages is an important means to enhance user browsing experience and extend user stay time.When a user finishes reading an article, these links can guide them naturally to discover more related content, avoid interrupting page browsing, and effectively reduce the bounce rate, which also helps to enhance the overall weight of the website's content. AnQi CMS as a rich-featured Go language content management system, built-in with a powerful template tag system, allowing website operators to flexibly control content display. Among which

2025-11-09

How to accurately display the detailed content of a specific AnqiCMS document on the front page, including the title, description, and image?

AnQiCMS (AnQiCMS) leverages its flexible content model and intuitive template tag system, allowing you to easily manage the display of website front-end content.It is particularly important to understand the core mechanism and common tags when we need to present the detailed content of a specific document accurately on the front page, such as the title, description, full text, and related images.### Understanding the content structure of Anqi CMS In Anqi CMS, all content is organized based on the "content model", such as common article models, product models, etc.

2025-11-09

How to use AnqiCMS document list tags to display the latest, hot, or specified category of articles/products on the front page?

In AnqiCMS, flexibly displaying website content is the key to improving user experience and meeting operational needs.Whether you want to highlight the latest articles on the homepage, display popular products in the sidebar, or customize content lists for specific columns, AnqiCMS's powerful document list tags can help you a lot.By skillfully using these tags, you can easily achieve a diverse presentation of content, making your website more dynamic and attractive.### Core Tag: `archiveList`

2025-11-09

How to implement the AnqiCMS document parameter filtering function on the front page to help users quickly locate content?

How to help users quickly find the information they are interested in on increasingly rich content websites is a crucial operational challenge.Users often need to filter content based on specific conditions rather than browsing aimlessly.AnqiCMS provides a powerful document parameter filtering function that allows you to easily achieve this goal on the front page, greatly enhancing user experience and content discoverability.

2025-11-09

How to display the AnqiCMS document Tag list on the front page and support filtering by letter or category?

In a content management system, a tag (Tag) is a powerful tool that helps us organize content more flexibly and improve the efficiency of users in finding relevant information.AnQiCMS as an efficient enterprise-level content management system naturally also deeply integrates powerful tag features.If you are hoping to display a list of document tags on the website front end and allow users to filter by letter or category, this article will provide you with a comprehensive guide.

2025-11-09

How to display detailed information of a specific AnqiCMS Tag on the front page, such as description and Logo?

AnqiCMS as an efficient content management system not only provides rich content publishing and management functions, but also provides great flexibility for the display of front-end pages.In website operation, properly using tags (Tag) can effectively enhance the organization of content, user experience, and search engine optimization (SEO).When a user browses to a specific tag, if the page can directly display the detailed information of the tag, such as its description and exclusive Logo, it will undoubtedly greatly enhance the professionalism and attractiveness of the page.Next, we will explore how to use the AnqiCMS front page

2025-11-09

How to display the document list associated with a specific Tag of AnqiCMS on the front page?

In website content operation, effectively organizing and displaying related content is crucial for improving user experience and the SEO performance of the website.The AnqiCMS Tag (tag) feature is exactly for this purpose.By cleverly using Tag, we can not only provide users with more accurate content navigation, but also make search engines better understand the structure of the website content. This article will focus on how to clearly and effectively display the document list associated with a specific Tag in AnqiCMS on the front page of a website.###

2025-11-09