How to customize the content model field and flexibly call it to display its content in the template?

Calendar 78

One of the core advantages of AnQiCMS in content management is its flexible and customizable content model.This allows us to no longer be limited by fixed content structures, and be able to create personalized content types that meet the actual operational needs of the website.No matter if you are publishing technical articles, displaying product details, or managing event information, customized content model fields can help you accurately construct the content structure you need, and ultimately flexibly display it on the website front end.

Below, let's take a look at how to customize the content model fields in AnQiCMS and flexibly call their content in the template.

1. Understanding the value of custom content models

Imagine, your website needs to publish various types of content: technical blog posts require authors, publishing platforms, technology stacks, and other information;And product display may require product model, price, stock, detailed parameters, etc.Traditional CMS often only provide general fields such as "title", "content", etc., and to add these specific information, it may be necessary to hard-code them into the content, which is not standardized and不利于 management and search.

AnQiCMS's custom content model mechanism allows you to add exclusive fields for different content types (such as "articlesThese fields are like the 'DNA' of content, defining all the information that each type of content should contain, thus achieving structured management of content.This makes content entry clearer and more efficient, and also provides great flexibility for front-end display. You can call and display the content of each field accurately according to your needs.

Define custom fields in AnQiCMS backend

The settings for custom fields are performed under the "Content Model" in the "Content Management" module.AnQiCMS comes with two basic models, 'Article Model' and 'Product Model'. You can directly edit them or create a new custom model.

  1. Enter content model management:Log in to the AnQiCMS backend, navigate to 'Content Management' -> 'Content Model'. Here, you will see a list of all existing content models.

  2. Edit or create a model:Select a model you want to add a custom field to (for example, 'Article Model' or 'Product Model'), click the 'Edit' button next to it.If you want to start from scratch, you can also click 'Add New Model' to create a completely new content model.

  3. Add custom field:On the model editing page, you will see the "custom field" area of the content model.This is where you define your personalized field.

    • Parameter name:This is the name displayed in the background management interface, which is also a Chinese description convenient for you to understand the field usage, such as 'article author', 'product model', 'service features', etc.
    • Call field:This is the unique identifier actually used to call this field in the template,Must use English lettersIt is recommended to use all lowercase or camel case, for example,author/modelNumber/features. This name is very important, and it will be used to retrieve data in the template later.
    • Field type:AnQiCMS provides various field types to meet different data input requirements:
      • Single-line text:Applicable to short text information, such as author name, product model.
      • Number:Only numbers are allowed, such as price, stock quantity.
      • Multi-line text:Applicable to longer text, such as product introduction, service description.
      • Single choice/Multiple choice/Dropdown choice:Suitable for scenarios where preset options are provided for selection, such as product color (single selection), service scope (multiple selection). These options need to be filled in one per line in the "default value
      • Image group/file group:Suitable for uploading multiple images or files.
    • Mandatory?:Tick this box, the field will become a required field when publishing content.
    • Default:You can set a default value for the field. If it is a selection type field, it is used here to fill in all available options, one per line.

    After adding and configuring the field, be sure to click the "Save" button at the bottom of the page to make the changes take effect.

3. Fill in the custom fields when publishing content.

After you have defined the custom field, go back to the 'Content Management' module, select 'Add New Document' or edit an existing document, and choose a category associated with the model you just modified or created.For example, if you add a field in the "Product Model", then when publishing a category under the "Product Model", these custom fields will automatically appear in the "Other Parameters" collapse area of the document editing page, waiting for you to fill in the corresponding content.This greatly simplifies the content editing process, ensuring the integrity and standardization of the content.

Four, flexibly call custom field content in the template

The power of custom fields lies in their ability to be accurately captured and displayed by AnQiCMS template tags. AnQiCMS's template engine is similar to Django syntax, using{{变量}}Output content,{% 标签 %}Control logic.

1. Call the custom field of a single content on the detail page

On the document detail page (for example{模型table}/detail.htmlWe usually need to display all the details of the current document.

  • Directly call the known field name:If you know the name of the custom field's 'call field', you can use it directly.archiveDetailLabel to get its value. For example, you added a field namedauthorThe field (called field) "article author" (parameter name):

    <p>文章作者:{% archiveDetail with name="author" %}</p>
    

    Or perhaps added to the "product model"productPriceField:

    <p>产品价格:{{ archive.productPrice }} 元</p> {# 简单字段也可以直接通过archive.调用字段名访问 #}
    
  • Loop through all custom fields:Sometimes, you may want to display all the additional information of the document without specifying each one.archiveParamsLabels can help you traverse all the custom fields set.

    {% archiveParams params %}
        <div class="custom-fields">
            {% for item in params %}
                <p>{{ item.Name }}:{{ item.Value }}</p>
            {% endfor %}
        </div>
    {% endarchiveParams %}
    

    Here, item.NameIt is the "parameter name" you set in the background (such as "article author"),item.ValueThe actual value you enter when publishing content.

  • Handle special field types (such as image groups, multiple choices):For image groups, multiple choice types, and other fields that return arrays or lists, you need to use loops to display. For example, you define a named `

Related articles

How to use the recommendation attribute (Flag) of AnQi CMS to display featured content on the homepage or special page?

AnQi CMS provides an efficient way to manage and highlight important content on your website, that is, through the "recommended attribute" (Flag).This feature allows you to easily display carefully selected content on the homepage, special pages, or other key positions, thereby guiding visitors' attention and enhancing the interactivity and information transmission efficiency of the website. ### Recommended Attribute Settings: The First Step of Content Selection In the AnQi CMS backend, the starting point of content management is to publish or edit documents.When you are ready with high-quality content, you hope it will stand out at a key position on the website

2025-11-08

How does Anqi CMS implement seamless language switching and display of multilingual content on the front-end page?

Today, with the deepening of globalization, website content that can reach users of different languages has become a key factor in enterprises expanding the market and enhancing brand influence.AnQiCMS (AnQiCMS) is well aware of this need, and from the very beginning of system design, it has made multilingual support one of its core features, aiming to help users easily switch and display content seamlessly on the front-end page.How does Anqi CMS help us build and manage multilingual websites and allow visitors to switch between different language versions smoothly?

2025-11-08

How to accurately retrieve and display a specific article list based on category ID?

In a content management system, effectively organizing and displaying content is crucial for improving user experience and website SEO performance.AnQi CMS with its flexible and powerful template engine allows you to easily implement the requirement of fetching and displaying a list of articles based on a specific category ID.Whether it is to build a special page, category archive, or simply to display the latest content of a specific column on the homepage, Anqi CMS can provide intuitive and efficient solutions.This article will deeply explore how to utilize the template tag feature of Anqi CMS, especially the `archiveList` tag, to accurately achieve this goal

2025-11-08

How to customize the display layout and elements of the AnQi CMS article detail page?

In AnQi CMS, managing and displaying content is a core function, and the article detail page, as an important interface for users to obtain information and interact with the website, is directly affected by the display layout and design of the elements, which in turn affects user experience and information communication efficiency.AnQi CMS provides high flexibility, allowing users to deeply customize the display of article detail pages according to their own needs. To customize the article detail page, you first need to understand the Anqi CMS template system.It uses syntax similar to the Django template engine, template files are usually suffixed with .html

2025-11-08

How to set up an independent template for the single page of AnQi CMS to achieve highly personalized display?

In website operation, we often encounter such needs: some single pages, such as 'About Us', 'Contact Information', or 'Product Download' pages, need to have unique layouts and functions to provide a more unique user experience or carry specific marketing goals.AnQi CMS understands the importance of personalized display and therefore provides a very flexible way for us to tailor exclusive templates for each single page, achieving highly personalized display effects.

2025-11-08

How to control the automatic lazy loading of images in the article content of AnQi CMS

In website operation, page loading speed and user experience are crucial aspects.Especially for articles that contain a large number of images, the loading of images often becomes the 'culprit' that slows down the page speed.At this time, the image lazy loading (Lazy Loading) technology is particularly critical.AnQi CMS deeply understands this, providing a simple and efficient way to control the automatic lazy loading of images in article content, helping your website to improve performance and user experience.Why is lazy loading of images so important? Lazy loading of images is a strategy of deferred loading

2025-11-08

How to display website name and Logo in AnQiCMS?

The website's name and logo are like the face of a brand, they are not only the first impression visitors have of you, but also an important manifestation of the website's professionalism and recognition.In AnQi CMS, setting and displaying your website name and logo is a straightforward and efficient process.Next, we will explore how to perfectly present these key elements on your website. ### First, set up the website name and Logo To make your website have a unique name and Logo, the first step is to configure it in the Anqi CMS backend management interface.1. **Enter Global Settings**

2025-11-08

How to obtain and display the filing number of the AnQiCMS website?

For websites operating in mainland China, the filing number (ICP number) is an indispensable element.It is not only a requirement of laws and regulations, but also an important symbol to enhance the credibility of the website and gain the trust of users.AnQiCMS knows this point and therefore considered convenient management and display of the filing number at the very beginning of system design, allowing website operators to easily complete the configuration. Next, we will together learn how to obtain (configure) and display the filing number on the AnQiCMS website.

2025-11-08