How to retrieve and display custom parameters of content models such as articles, products, etc. in a template?

Calendar 👁️ 73

In AnQi CMS, when managing website content, we often encounter the need to display specific information in addition to standard fields such as title and content.For example, when operating an e-commerce website, in addition to the name and description of the product, you may also need to display "material", "origin", "warranty period", and so on;Or you are running a news blog, articles may need to display 'author source', 'publishing institution', and so on.Flexible content model design of Anqi CMS is exactly to meet the demand of diverse content display.

Today, let's delve into how to obtain and elegantly display custom parameters in the Anqi CMS template for content models such as articles, products, etc., making your website content richer and more structured.

Why do we need custom parameters for the content model?

AnQi CMS provides various preset content types such as 'Article Model' and 'Product Model', but the detailed needs of content for each industry and each website are very different. Custom parameters allow you:

  1. Enrich the dimensions of content:Break through the limitations of traditional content, add any additional information you consider important to articles and products.
  2. Improve user experience:Present information in a structured manner so that visitors can easily find the key data they are interested in, such as the core selling points of a product or the unique background of an article.
  3. Optimize content management:Categorize different information, which makes background entry and management clearer and more efficient.
  4. Enhance SEO effects:Structured data is easier for search engines to understand and crawl, which helps improve the visibility and ranking of the website.

In short, custom parameters are the foundation for personalizing and professionalizing your website content.

How to set custom parameters in the background?

In AnQi CMS, the process of setting custom parameters is very intuitive. You can follow the following steps:

  1. Enter content model management:Log in to the Anqi CMS backend, find the "Content Management" on the left navigation bar, and then click "Content Model".
  2. Select or create a model: You can choose to edit an existing 'article model' or 'product model', or create a content model as needed.
  3. Add custom field:On the model editing page, you will see the "Content Model Custom Field" area. Click "Add Field" to define new parameters for the current model.
    • Parameter name:This is the Chinese name displayed on the backend, for your understanding (for example, 'article author').
    • Call field:This is the actual English variable name used in the template, please ensure its uniqueness and easy recognition (for exampleauthor)
    • Field type:Select the data type you need to store (single-line text, number, multi-line text, single choice, multiple choice, drop-down selection).This will directly affect the input form on the backend and the display on the frontend.
    • Mandatory, default value: Set according to business requirements.
  4. Save settings:After adding custom fields, be sure to click Save.

After setting up the content model, when you add or edit articles or products under "Content Management", you will see the custom fields just defined in the "Other Parameters" section of the editing page, where you can enter corresponding data for each piece of content.

Retrieve and display custom parameters in the template

In Anqi CMS templates, we mainly use two ways to obtain and display these custom parameters: directly through field names, and by looping through all parameters. The Anqi CMS template engine is similar to Django syntax, using double curly braces{{变量}}Output, conditions and loops using{% 标签 %}the structure.

1. Directly get specific custom parameters through field names

If you know the name of the custom parameter "call field" and only need to get the value of a single parameter, you can usearchiveDetailThe tag is usually used on the details page of articles or products, and can obtain detailed information about the current document, including custom parameters.

Assuming you have added a custom parameter "article source" to the article model, its "call field" issource. In the article detail page template, you can retrieve and display it like this:

{# 假设当前是文章详情页,archiveDetail会自动获取当前文档的详情 #}
<div>
    <span>文章标题:</span>{{ archive.Title }}
</div>
<div>
    <span>发布时间:</span>{{ stampToDate(archive.CreatedTime, "2006-01-02") }}
</div>
<div>
    {# 直接通过自定义参数的“调用字段”名称来获取 #}
    <span>文章来源:</span>{% archiveDetail with name="source" %}
</div>

{# 如果您将获取到的值赋给一个变量,可以这样: #}
{% archiveDetail articleSource with name="source" %}
<div>
    <span>文章来源(变量):</span>{{ articleSource }}
</div>

Please note,nameThe value must be the 'trigger field' name that you set in the background. This method is concise and clear, suitable for situations where you know exactly which custom parameters to display.

2. Loop through all custom parameters

Sometimes, you may want to dynamically display all custom parameters, or you are unsure of the specific custom parameters of each content model. At this time,archiveParamsThe label comes into play. It can retrieve all custom parameters of a specified document and allows you to display them through a loop.

{# 获取当前文档的所有自定义参数,并将其赋给变量params #}
{% archiveParams params %}
    <div>
        <h3>其他参数:</h3>
        <ul>
            {% for item in params %}
            <li>
                <span>{{ item.Name }}:</span> {# item.Name 是参数名(例如“文章作者”) #}
                <span>{{ item.Value }}</span> {# item.Value 是参数的值 #}
            </li>
            {% endfor %}
        </ul>
    </div>
{% endarchiveParams %}

In the above example,paramsA variable is an array of objects containing all custom parameters, eachitemincludesName(parameter name, that is, the Chinese name set in the background) andValue(Parameter value).

Handle custom parameters of a specific type:

If your custom parameters areMulti-line textorRich text(For example, a detailed "product feature introduction". The field type is multi-line text, and the background allows HTML input. To ensure that the HTML content is parsed correctly and not escaped, you need to use it in the output when)|safeFilter. If this field supports Markdown, it needs to be used first|renderThen use the filter to convert it to HTML|safe:

{# 假设自定义字段"产品特点介绍"的调用字段是"features", 且支持Markdown #}
{% archiveDetail productFeatures with name="features" %}
<div class="product-features">
    {{ productFeatures|render|safe }}
</div>

If your custom parameter is aimage group(For example, "product actual photos", multiple image addresses input in the background),`

Related articles

How does Anqi CMS handle images in content to optimize loading speed and display quality (WebP, compression)?

In the content of the website, images play a crucial role, they can enrich the visual effects and convey complex information.However, unoptimized images are often the culprit for slow website loading and poor user experience.As content operators, we fully understand the value of image optimization in improving website performance and user retention.AnQiCMS provides a series of powerful and intelligent functions in image processing, aiming to help us easily achieve a balance between image loading speed and display quality.

2025-11-08

How to embed and display mathematical formulas or flowcharts from the Markdown editor in the content?

In modern content operation, the professionalism and readability of the content are equally important.Especially when our website involves fields such as science, education, engineering, and so on, how to clearly and beautifully present complex mathematical formulas or logically rigorous flowcharts in articles often becomes the key to improving user experience.AnQi CMS understands this need, integrating a powerful Markdown editor and combining it with simple frontend configuration, allowing your website to easily present these professional contents.### First Step

2025-11-08

How to display system-level configurations such as the website logo, filing number, copyright information, etc.

The brand identity, legal statements, and core contact information, such as Logo, filing number, and copyright information, are an indispensable part of the professional image of a website.They not only convey trust and standardization to visitors, but are also important aspects of search engine optimization and legal compliance.In Anqi CMS, managing and displaying these system-level configurations becomes extremely intuitive and efficient. ### Backend Settings: The "Control Center" of Website Information AnQi CMS concentrates these core website information in the "Global Settings" of the backend, making management clear at a glance.

2025-11-08

How to build and display a custom field comment form on the front-end page?

When you want website visitors to be able to interact with you, such as submitting questions, providing feedback, or making appointments, a well-functioning contact form is essential.AnQiCMS provides a very flexible and powerful message management function, the core of which is to support custom message fields, allowing you to build personalized forms according to your actual business needs.This article will guide you on how to build and display these comment forms with custom fields on the front-end page.Why do you need a custom message form?

2025-11-08

How to dynamically display the name, description, and link of content categories in a template?

In website operation, clearly displaying content categories not only helps users quickly find the information they need, but is also a key link to improve website usability and search engine optimization (SEO).AnQiCMS (AnQiCMS) with its flexible template engine allows us to easily dynamically call and display the names, descriptions, and links of various content categories in website templates.Today, let's delve deeper into how to achieve this goal in templates, making your website content more vivid and efficient.### Understanding Content Classification in AnQi CMS In the AnQi CMS backend management system

2025-11-08

How does AnQi CMS display detailed content of a single page (such as About Us, Contact Information)?

In website operation, pages such as "About Us", "Contact Information", and "Privacy Policy" play a crucial role. They are the basis for visitors to show corporate information and establish trust.AnQiCMS as an efficient content management system provides a very flexible and intuitive way to create and display the detailed content of these single pages.

2025-11-08

How to display the list of article tags (Tag) and the related articles under each Tag?

AnQi CMS provides very flexible and powerful tools for content organization, among which tags (Tag) are a very intuitive and efficient tool.By using labels reasonably, not only can it help us better manage website content, but also significantly improve user experience and search engine optimization (SEO) effects.Next, let's take a look at how to display the list of article tags in Anqi CMS, as well as the related articles under each tag.### First step: Manage and create tags in the background Before using tags, make sure that our website content has been properly tagged

2025-11-08

How to implement pagination control for content list display in Anqi CMS?

In website operation, how to efficiently display and manage a large amount of content while ensuring a smooth browsing experience is a challenge that every webmaster needs to face.AnQiCMS provides an intuitive and powerful control capability for pagination display of content lists, allowing you to easily achieve an orderly presentation and efficient navigation of content.To implement the pagination display of content lists, we mainly use two core tags in Anqi CMS templates: content list tags (such as `archiveList`, `tagDataList`

2025-11-08