How to display custom field content of different content models in the frontend template?

Calendar 👁️ 62

The content model feature of AnQiCMS brings great flexibility to website operations, allowing us to define various personalized content structures according to the actual needs of the business.Whether it is an article, product, event, or any other custom content type, we can add unique fields to it.How can we flexibly display the custom fields in the content models on the website front-end template?Let's explore this practical skill together.

Understanding AnQiCMS content models and custom fields

When using AnQiCMS for content creation, we are not limited to basic fields such as article title and content.Through the content model feature, we can create dedicated data fields for different types of content.For example, if your website needs to display product information, you may add custom fields such as 'Product Model', 'Product Model Number', 'Product Color', 'Stock Quantity', 'Product Details Gallery', and so on.These fields make your content more structured and facilitate quick access to the information you need.

These custom field settings are usually found under the 'Content Model' feature in the 'Content Management' section of the AnQiCMS backend.Here, you can choose to edit an existing model (such as "Article Model" or "Product Model"), or create a new content model.In the model editing interface, you will see a region for "content model custom fields".Here, we can add new fields and specify their 'parameter name' (for backend display), 'field name' (for frontend template, it is recommended to use lowercase letters and unique), 'field type' (such as single-line text, number, multi-line text, single selection, multiple selection, dropdown selection, etc.), as well as whether it is required and the default value.

For example, suppose we add a custom field named "Product Model" with the "field name" set tomodel_number. We may also have added a 'Product Highlight' field, whose 'trigger field' ishighlights, field type is 'Multi-line text', used to describe the product's unique advantages.

Display custom field content in the front-end template

AnQiCMS front-end template uses syntax similar to Django, variables are passed through double curly braces{{ }}output while the label is used{% %}wrapped. When we need to display custom fields of the content model in a template, we mainly usearchiveDetail/categoryDetailorpageDetailetc. detail tags, as well asarchiveParams.

1. Show single custom field content

If you know exactly which custom field to display and it is typically a single-line text or a number, you can use it directly.archiveDetailTag (in document detail page),categoryDetailTag (in category detail page) orpageDetailTag (in single page detail page) to call.

For example, on the product detail page, we want to display the product model (model_number):

<p>产品型号:{% archiveDetail with name="model_number" %}</p>

If you wish to assign this value to a variable for later use, you can also do it like this:

{% archiveDetail productModelNumber with name="model_number" %}
<p>产品型号:{{ productModelNumber }}</p>

This method is concise and clear, suitable for scenarios where we know the custom field names.

2. Process custom fields containing multiple or rich text content

The type of some custom fields may be multiple choice, group images, or rich text content like 'Product Highlights'.These fields' data is usually stored in arrays or with HTML structure, and we need to handle it specially.

Multi-value fields (such as: product galleries, multiple selections):If your custom field (such asproduct_imagesIt stores an array of images or multiple choice values, you need to combineforloop to traverse and display them.

{% archiveDetail productImages with name="product_images" %}
<div class="product-gallery">
    {% for image in productImages %}
        <img src="{{ image }}" alt="产品图片">
    {% endfor %}
</div>

Rich text or Markdown content:When the custom field type is a multiline text editor (usually supporting rich text editing or Markdown format), the content may contain HTML tags. In order to ensure that these contents can be correctly parsed and displayed by the browser and styles, we need to use|safeFilter. If the background content settings have enabled the Markdown editor and the field content is in Markdown format, then it is necessary to use first|renderThe filter converts it to HTML and then|safefilter.

For example, display “Product highlights” (highlights) the content of the field:

{# 假设 highlights 是富文本内容 #}
<div class="product-highlights">
    {{ archiveDetail with name="highlights" | safe }}
</div>

{# 假设 highlights 是 Markdown 内容,且后台启用了 Markdown 编辑器 #}
<div class="product-highlights">
    {{ archiveDetail with name="highlights" | render | safe }}
</div>

Tip:When you are on the list page (such asarchiveListWithin the loop) When you need to display custom fields, you can directly accessitem.自定义字段名for example{{ item.model_number }}.

3. Dynamically traverse and display all custom fields

If you want to display all custom fields and their values dynamically under a content model in a template (for example, in the product parameter area),archiveParamsLabels can be very useful. They will return a list of custom fields, you can iterate through them withfora loop.

<div class="product-parameters">
    <h3>产品参数</h3>
    {% archiveParams params %}
        {% for item in params %}
        <p>
            <span>{{ item.Name }}:</span> <!-- 自定义字段的显示名称 -->
            <span>{{ item.Value }}</span> <!-- 自定义字段的值 -->
        </p>
        {% endfor %}
    {% endarchiveParams %}
</div>

Hereitem.NameIt will display the parameter name you set in the background (for example, the product model), anditem.ValueThe content filled in this field will be displayed. This is especially convenient for building flexible product parameter tables or information blocks.

If a certainitem.ValueField contains HTML or Markdown content, don't forget to add|safeor|render|safefilter.

4. Call to custom fields of other content models

In addition to document models, category models and single pages can also have custom fields. The calling method is similar to that of document models, just replace the tag name withcategoryDetailorpageDetailJust do it.

For example, display the custom 'feature description' field of the category on the category detail page (using the field namefeature_desc):

<div class="category-feature">
    <h4>特色描述</h4>
    {{ categoryDetail with name="feature_desc" | safe }}
</div>

Practical suggestions

  • Naming conventions:When setting up custom fields in the background,“field name”

Related articles

How to implement batch replacement of specific keywords in article content and display it on the front end in AnQiCMS?

In the daily work of content operation, we often encounter the need to make uniform adjustments to a large amount of article content.This may involve updating the brand name, correcting industry terminology, unify the product model, and even adjusting keyword density for SEO purposes.Manually modifying hundreds or even thousands of articles one by one is undoubtedly a huge task and is prone to errors.AnQiCMS provides a very practical feature that can help us efficiently implement batch replacement of specific keywords in article content and ensure that these changes are displayed correctly on the website front-end.Why do you need to replace keywords in articles in bulk

2025-11-07

How to display the title and link of the previous and next articles on the article detail page?

In AnQi CMS, adding the titles and links of the previous and next articles to the article detail page can not only optimize the user experience on your website, guide them to discover more related content, but also improve the internal link structure of the website to a certain extent.AnQi CMS with its simple and efficient template engine makes the implementation of this feature very intuitive.### Core Feature Revelation: prevArchive and nextArchive Tags The AnQi CMS template system is built-in with two tags specifically designed for handling article navigation: `prevArchive`

2025-11-07

How does the AnQiCMS template format timestamps and display them in a specified date and time format?

In AnQiCMS template, easily format timestamps: Custom date and time display guide In website operation, content publishing time, update time, comment time, and other date information are an important part of the information we convey to visitors.Most of the time, the time data obtained from the database is usually a timestamp (a string of numbers), which is not intuitive for users.How to convert these original timestamps into a readable date and time format, and flexibly adjust the display according to the page design, which is a frequently encountered demand in template development. AnQiCMS

2025-11-07

How to only display documents of the current category on the category list page and not include documents of subcategories?

When operating a website, we often encounter the need to display content, one common scenario being how to precisely control the displayed content on a category list page.Sometimes, we hope to display documents under a main category page, including all subcategory documents as well, to provide more comprehensive information.However, in some cases, in order to maintain the purity of the page theme and the focus of the content, we may only want to strictly display the documents under the current category without including any content from subcategories.AnQi CMS as a flexible content management system

2025-11-07

Does AnQiCMS website support automatically converting uploaded images to WebP format to speed up display speed?

The loading speed of a website is an important factor for user experience and search engine optimization.Among them, images play an important part in the page content, and their loading efficiency has a significant impact on the overall performance of the website.WebP is a modern image format, compared to traditional JPEG, PNG, it can provide similar or even higher image quality with smaller file size, thereby significantly speeding up web page loading speed.AnQiCMS as a content management system that focuses on efficiency and performance, fully considers the optimization needs of the website in image processing.For "AnQiCMS"

2025-11-07

How to display the name and link of the current article's category in a frontend template?

In website content operation, the classification information of articles not only helps users quickly understand the content attribution, but also is the key to improving the website navigation experience and search engine optimization (SEO) effect.For friends who use AnQiCMS to build websites, it is a very practical and basic requirement to accurately display the name of the category to which each article belongs and provide a link.AnQiCMS provides powerful and flexible template tags, allowing us to easily achieve this function.### Skillfully Utilize `archiveDetail`

2025-11-07

How to display the filing number and copyright information at the bottom of the website in AnQiCMS?

During the operation of a website, whether it is to meet the requirements of laws and regulations or to enhance the professionalism and user trust of the website, clearly displaying the filing number and copyright information at the bottom of the website is an important aspect.AnQiCMS as an efficient content management system provides a very flexible and intuitive way to configure and display these key information. Next, we will introduce step by step how to set and display the filing number and copyright information at the bottom of the AnQiCMS website.### The first step: Fill in the filing number and copyright information in the background First

2025-11-07

How to add watermarks to images on the AnQiCMS website to protect original content?

In today's increasingly rich digital content, protecting the copyright of original works is particularly important, especially for visual content such as images.When your website publishes a large number of carefully crafted images, if they are not protected, it is easy for others to copy and repost them arbitrarily, which not only infringes on your labor results but also weakens the uniqueness of the content.Adding a watermark to an image is a simple and effective means of copyright protection, which can clearly assert ownership of the content without affecting the beauty of the image, effectively deterring unauthorized use.Anqi CMS as a highly efficient

2025-11-07