How to define a new field in a custom content model and flexibly call and display these fields on the front-end page?

Calendar 👁️ 62

In AnQi CMS, utilizing a custom content model to manage and display personalized content is one of its core advantages.This allows us to flexibly create dedicated data structures for different types of content based on specific business needs.This article will discuss in detail how to define these custom fields in the background, as well as how to cleverly call and display them on the front-end page.

Define a new field in the background content model

The content model is like a 'blueprint' for content, which determines what information each type of content (such as articles, products, cases, etc.) should include.We need to start from the Anqi CMS backend management interface to define a new field.

First, please go to the "Content Management" section of the background management interface and find the "Content Model" option.Here, you can see the system-built article model, product model, and also create a new content model.Whether it is to edit an existing model or create a new model, the core operations are similar.

Click on the edit page of any content model, and you will see the 'Custom fields of content model' area.This is where we flex our muscles. Click 'Add field' to appear a form, which needs to fill in the following key information:

  1. Parameter NameThis is the Chinese name displayed on the background editing interface for administrators, which is convenient for understanding and management, such as 'article author', 'product size', etc.
  2. Field invocationThis is the name stored in the database field, and it is also the unique identifier used in the front-end template. Please make sure to use letters, such asauthor/size. This name is crucial when called in the template.
  3. Field type: Anqi CMS provides various field types to meet different data requirements. Common ones include:
    • Single-line text: Suitable for short text input, such as titles, brief descriptions, etc.
    • Number: Only numeric input is allowed, suitable for prices, inventory, quantities, etc.
    • Multi-line text: Suitable for long text content, such as product descriptions and detailed explanations.
    • Single choice: Provides preset options, the user can only choose one, such as "Color: Red, Blue, Green".
    • Multiple selectionsProvide preset options for users to select multiple, for example, 'Features: Waterproof, Dustproof, Durable.'
    • Drop-down selectionSimilar to single choice, but presented in the form of a dropdown menu.
    • For the selection field, you still need to enter an option on each line in the "default value".
  4. Mandatory?: It can be set to determine whether the field must be filled in when the content is published.
  5. Default valueSet an initial value for the field, if the content is not filled in when published, the system will automatically use this default value.

After you have defined these custom fields for the content model, save the settings.After you choose this content model to publish articles, products, or any other content, you will see these newly added fields in the "Other Parameters" collapsible area on the content editing page, and you can fill in the corresponding content as needed.

Flexibly call and display these fields on the front-end page.

The true value of well-defined custom fields lies in the display on the front-end page. Anqi CMS provides flexible template tags that allow us to easily retrieve and render this data.

First, for some basic fields that the content model itself comes with, such as the document titleTitleDocument contentContent、ThumbnailThumbetc., they are usually included inarchivethis global variable. You can directly go through the detail page to{{ archive.Title }}/{{ archive.Content|safe }}This way is easy to call. Among other things,|safeFiltering forContentRich text fields are particularly important, as they ensure that HTML tags are parsed correctly and not displayed as plain text, but also pay attention to content security.

For our custom new field, the calling method is more flexible:

  1. Call specific fields directly by nameIf you know the name of the "call field" of the custom field (for example, as defined earlier in this document)authororsize), you can usearchiveDetailLabel to get and directly display it. This method is very suitable for when you know exactly which field to display.

    For example, to display the field "Article Author":

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

    Or, if you want to store the field content in a variable to use it later:

    {% archiveDetail articleAuthor with name="author" %}
    <p>文章的撰写者是:{{ articleAuthor }}</p>
    

    This method is concise and clear, directly pointing to a specific field, suitable for displaying specific information at a fixed position on the page.

  2. Loop through all custom fieldsIn some cases, you may want to dynamically list all the custom parameters of a content item, for example, listing all the technical specifications on a product details page. At this point,archiveParamsA tag can be put to use. It will return an array or map containing all custom fields.

    UsearchiveParamsWhen you tag, you can assign it to a variable (for example,paramsThen proceedforLoop to traverse these fields:

    <div class="custom-fields">
        {% archiveParams params %}
        {% for item in params %}
        <div class="field-item">
            <span class="field-name">{{ item.Name }}:</span>
            <span class="field-value">{{ item.Value|safe }}</span> {# 注意:如果自定义字段可能包含HTML,请使用 |safe #}
        </div>
        {% endfor %}
        {% endarchiveParams %}
    </div>
    

    In this loop,item.NameIt will display the field's 'parameter name' (i.e., the Chinese name displayed in the background),item.ValueThe actual content of this field should be filled. If you have a custom field of rich text type, it should also be used in the same way|safeThe filter ensures that it is rendered correctly.

    You can even base it onitem.Nameoritem.ValuePerform conditional judgment, only display fields that meet specific conditions, or perform special processing on certain fields. For example, you can add in the loop.{% if item.Name == '产品颜色' %}Target specifically handle the display of the 'Product Color' field.

Through these two flexible calling methods, whether it is to precisely control the display position of a single custom field or to dynamically traverse and display all additional information, Anqi CMS can provide strong support to help you easily build highly customized website content.

Frequently Asked Questions (FAQ)

  1. Ask: Why can't I see the custom field I defined on the content editing page? Answer:Please confirm that you have defined the fields under the correct content model.The custom field is associated with a specific content model. When publishing or editing content, you must first select or the category of the content must be associated with the content model for which you have defined the custom fields, then these fields will be displayed in the 'Other Parameters' area.If the selected model does not match, the fields will naturally not appear.

  2. Ask: How can I call the image address in the custom field in the front-end template? Answer:If your custom field type is "image upload" or "multi-image upload", when calling in the template,item.Value(if it passes),archiveParamsor directly call the field name (if it passes)archiveDetailThe call will return the URL of the image. You can directly use this URL as<img>label'ssrcan attribute value to display the image, for example:<img src="{% archiveDetail with name="myImageField" %}" alt="自定义图片" />If it is a multi-image, you need to traverse the array of image URLs again.

  3. Question: Does the custom field support multilingual? How to implement it? Answer:The AnQi CMS supports multilingual functionality, and the content of custom fields can also be multilingual.When defining custom fields, you do not need to make any additional settings. In the background content editing page, when you switch to different language versions to edit the content, each language version's custom fields can be independently filled with the content of their respective languages.When the front-end template is called, the system will automatically pull the custom field content corresponding to the current website language setting for display.

Related articles

How can AnQi CMS display image watermarks or anti-crawling interference codes on the front end to protect original content?

In the current information explosion of the Internet environment, the value of original content is increasingly prominent.However, content plagiarism and malicious scraping have also become a major headache for many website operators, not only damaging the creators' labor results, but also possibly affecting the website's search engine rankings and brand reputation.Faced with this challenge, AnQiCMS (AnQiCMS) fully understands the importance of content protection, and is built-in with front-end image watermarking and anti-crawling interference code functions, aiming to provide a solid defense line for your original content.### Understand the necessity of content protection Before discussing specific features

2025-11-08

How to clearly display the user's input search keywords and related documents on the search results page?

In Anqi CMS, create a highly efficient and user-friendly search results page that can not only help visitors quickly find the information they need, but can also significantly improve the overall professionalism and conversion rate of the website.This article will delve into how to clearly display the search keywords and related documents entered by users under the powerful functions of AnQi CMS.Build a dedicated search page template: Clearly show user intent The template system of Anqi CMS is known for its high flexibility, allowing you to customize each page according to your business needs.The search results page usually corresponds to the current template directory under

2025-11-08

How to configure the pagination display of the article list and allow custom pagination links and styles?

In website operation, as the content volume grows, how to effectively organize and present these contents so that users can easily browse them is the key to improving user experience and website performance.The pagination display of the article list is an important means to achieve this goal.AnQiCMS provides a powerful and flexible template tag feature, allowing us to easily configure the pagination display of article lists and customize the link structure and visual style of pagination according to actual needs.### Configure the article list to enable pagination Enable pagination for the article list

2025-11-08

How to automatically generate and display breadcrumb navigation that conforms to SEO standards on a webpage?

In website operation, providing clear navigation paths for visitors while optimizing the crawling efficiency of search engines is a key link to improve user experience and website SEO performance.A breadcrumb navigation is a feature that can intuitively display the hierarchical position of the user on the current page and provide a convenient return path.For websites built using AnQiCMS, we can conveniently utilize its built-in features to automatically generate and display breadcrumb navigation that complies with SEO standards.###

2025-11-08

How to control the article list to only display documents under the current category and not include content from its subcategories?

When managing website content in Anqi CMS, we usually organize articles into different categories to form a clear hierarchical structure.This structure provides great convenience when managing content in the background.However, when displaying the list of articles on the front-end page, we sometimes need to control the display range of content more accurately, for example, we only want to display the articles directly published under the current category, and not include the content of its subcategories.Luckyly, AnQi CMS provides a simple and powerful solution for this: using the `archiveList` template tag's `child`

2025-11-08

On the article detail page, how to obtain and display a list of recommended articles related to the current article?

In website content operation, improving user stay time and reducing bounce rate is the goal pursued by every operator.After a user reads an article, if they can immediately see other content that interests them, it will undoubtedly greatly enhance their engagement, thereby improving the overall interactivity and user experience of the website.While AnQiCMS (AnQiCMS) is a powerful content management system, it provides us with convenient tools to implement intelligent recommendations for article detail pages without complex development work.The list of recommended articles not only provides users with a deeper reading experience, but also guides them to browse more website content

2025-11-08

How to retrieve and display the global settings information of a website, such as the website name, Logo, and filing number in the template?

When building website templates in AnQiCMS, we often need to display some general information at the website level, such as the name of the website, Logo image, and legal filing number required by law.This information is usually managed in the background global settings to ensure consistency across the entire site and ease of maintenance.AnQiCMS has a powerful template tag system, especially the `system` tag, which makes it very intuitive and efficient to obtain and display these global settings in the template.### Understanding Global Settings and `system`

2025-11-08

How to obtain and display the contact information configured on the back-end, such as phone numbers, email addresses, WeChat QR codes, and other diversified information?

AnQiCMS (AnQiCMS) is an efficient and flexible content management system that excels in helping enterprises display their brand image and provide convenient communication channels.For any website, having clear and easily accessible contact information is crucial for building trust with users and promoting cooperation.AnQi CMS deeply understands this, providing a set of intuitive and powerful functions that allow you to easily manage and display various contact information such as phone numbers, email addresses, WeChat QR codes, etc.### Backend Configuration: Central Management Center for Contact Information In AnQi CMS

2025-11-08