How to flexibly display custom content model fields on the front page of AnQiCMS?

Calendar 👁️ 59

In the world of content management, flexibility is the key to website success.Most of the time, we find that the standard "article" or "product" content model does not fully meet our unique business needs, such as the need to add unique attributes such as "material", "size", etc. for a specific type of product, or to add information such as "registration deadline", "event location", etc. to the event detail page.At this time, the powerful custom content model function of AnQiCMS can fully display its prowess.

How do these custom fields we carefully design in the background cleverly and flexibly display on the front-end page?

The foundation of building a custom content model in the background

AnQiCMS knows the diverse needs of content structure.It allows us to create and configure our own content model based on business scenarios.This is like a customized 'information table' for different types of content.

To start, we will usually enter the AnQiCMS backend management interface, find the "Content Management" under the "Content Model" feature.Here, we can modify the built-in 'article model' or 'product model', or create a completely new custom model.

On the configuration page of the custom model, the most critical part is the "Custom field of content model". We will set several key properties for each field:

  • Parameter Name: This is the Chinese display name of the field, which is convenient for us to understand and manage in the background. For example, 'author', 'product material'.
  • Field invocationThis is the unique identifier for the field called in the template, it is usually recommended to use English lowercase letters or camel case, such as “author”, “productMaterial”.This name is the key for front-end display.
  • Field type:AnQiCMS provides various field types such as single-line text, numbers, multi-line text (supporting Markdown), single choice, multiple choice, dropdown selection, etc.Choose the appropriate type to ensure data validity and the convenience of front-end display.
  • Mandatory?: Determines whether the field must be filled in when content is published.
  • Default value: Especially for selection type fields, we can preset option values here, one per line.

After the configuration is completed, when we go to “Add Document”, select the corresponding content model category, these custom fields will appear in the “Other Parameters” area, waiting for us to fill in specific content.

Second, present custom fields skillfully on the front-end template

Completed the backend custom field configuration and content entry, next is to present them in the front-end template.AnQiCMS uses a syntax similar to the Django template engine, making field calls intuitive and powerful.

1. Directly call the known custom fields

If we clearly know the name of the 'reference field' of the custom field to be displayed, we can directly use it on the document detail page (or other supported pages)archiveDetailtags to obtain.

Suppose we add a custom field named "article source" to the "article model", with the "called field" set tosource. So in the article detail template, we can call it like this:

<p>文章来源:{% archiveDetail with name="source" %}</p>

If it is necessary to display this field on the list page (provided that the field is included in the data when the list is queried), then inarchiveListin the loopitemthe object, you can also access it directly:

{% archiveList archives with type="list" limit="10" showFlag=true %}
    {% for item in archives %}
    <li>
        <h3><a href="{{item.Link}}">{{item.Title}}</a></h3>
        <p>文章来源:{{item.Source}}</p> {# 这里的'Source'是小写'source'的驼峰转换形式,具体以实际数据结构为准 #}
    </li>
    {% endfor %}
{% endarchiveList %}

2. Flexibly traverse and display all custom fields

The most powerful flexibility of AnQiCMS is that even if we are not clear about which custom fields a model defines, we can still go througharchiveParamsLabels dynamically traverse and display them. This is very useful for developing general templates or dealing with frequent field changes.

archiveParamsThe tag can retrieve all custom fields and their values of the current document (or specified document) and return them as a iterable array object.

<div class="custom-fields-section">
    <h4>更多详情:</h4>
    {% archiveParams params %}
    <ul>
        {% for item in params %}
        <li>
            <strong>{{ item.Name }}:</strong> <!-- 显示后台设置的“参数名” -->
            <span>{{ item.Value }}</span> <!-- 显示字段值 -->
        </li>
        {% endfor %}
    </ul>
    {% endarchiveParams %}
</div>

In this example,paramsis an array that contains all custom field information.item.Namecorresponds to the parameter name set in the background (such as "article author"), anditem.ValueThis corresponds to the specific content of the field. This way, the front-end can automatically adapt and display regardless of how many custom fields are added or modified in the background.

3. Handling details of different field types

Different handling may be required when displaying fields of different types:

  • Multiline text (especially Markdown): If the backend content editor is enabled for Markdown and the custom field type is multi-line text, then when displayed on the frontend, it usually requires using|renderThe filter renders Markdown syntax to HTML and combines|safeThe filter, to prevent HTML code from being escaped and displayed directly.
    
    {% archiveDetail articleIntro with name="introduction" %}
    <div class="intro-content">{{ articleIntro|render|safe }}</div>
    {% endarchiveDetail %}
    
  • Image group fieldIf a custom field (such asgalleryImages) is used to store a set of images, thenitem.Valueor a directly called variable will be an array of image URLs. We need to useforLoop to traverse and display each image.
    
    {% archiveDetail gallery with name="galleryImages" %}
    <div class="product-gallery">
        {% for imgUrl in gallery %}
        <img src="{{ imgUrl }}" alt="产品图片" />
        {% endfor %}
    </div>
    {% endarchiveDetail %}
    
  • Select the type field: Single choice, multiple choice, dropdown selection, etc., itsitem.ValueWill be the value selected by the user (or multiple values, usually separated by commas). Output directly.

III. Tips and practices in practice **practice

  • Naming conventions for calling fieldsWhen setting up custom fields in the background, the name of the 'invoked field' should be concise, meaningful, and unique. It is a good practice to follow camelCase naming conventions, for example,productMaterial/eventDateThis can greatly improve the readability and maintainability of template code.
  • Utilize|safeand|renderBe sure to use for fields that may contain HTML or Markdown (such as multi-line text editor content).|safeThe filter ensures that the content is parsed correctly and not escaped as plain text. If Markdown is enabled,|renderthe filter is also indispensable.
  • Conditional judgment{% if %}Before displaying custom fields, get into the habit of using{% if item.Value %}or{% if fieldName %}to judge. This can avoid the appearance of empty titles or labels on the front-end page when a field has no content, enhancing user experience.
  • Differentiate field scenarios: AnQiCMS not only supports custom fields in document details (archiveDetail) and document parameters (archiveParams) but also supports custom fields like category details (categoryDetail) and single page details (pageDetail) Also has similar capabilities. You can add dedicated custom fields for these page types according to your business needs.
  • Make full use of the GoLang underlying advantages of AnQiCMSBased on Go language, AnQiCMS is built with high performance. It can be flexibly used with template tags and custom fields, which can help us quickly build efficient and customizable websites.

By the above method, AnQiCMS makes it easy to display custom content model fields on the front end, whether it is a direct and precise call or a dynamic general traversal, it can cope easily, truly realizing flexible content management and presentation.


Frequently Asked Questions (FAQ)

1. I added a custom field "Author Email" for the article model (the field name isauthorEmail), how do I display it on the article detail page?You can use in the article detail templatearchiveDetailtag to call directly: “`twig

Author email

Related articles

How to use the AnQiCMS Tag feature to associate and display related documents?

In today's increasingly complex content management, how to efficiently organize and present website content, allowing users to easily find the information they are interested in, while also improving the website's search engine performance, is a problem that every website operator is thinking about.AnQiCMS provides a series of powerful features to meet these challenges, among which, the Tag feature is undoubtedly a great tool for connecting and enriching content relationships.Tag, in the literal sense, is like various small tags attached to articles or products, which can cross traditional classification boundaries and bring together topics with the same theme

2025-11-07

How to automatically extract document content to generate a summary or thumbnail for list display in AnQiCMS?

How to present content in a list page in an attractive way while not requiring a lot of manual work in website operation?This is often a problem that troubles operators. AnQiCMS understands this pain point and provides us with a set of effective solutions through its powerful automation features, especially excelling in the automatic generation and application of document summaries and thumbnails.### Automatically extract document summaries, say goodbye to manual writing Imagine that after each article is published, you need to manually write a concise summary, what a time-consuming task that is

2025-11-07

How to add recommended attributes to AnQiCMS documents to affect the display sorting order on the front page list and detail pages?

In Anqi CMS, the recommended attribute is a very practical feature in content operation.It can help us classify content for marking, which in turn affects how the content is displayed on the front list or detail page, such as highlighting, prioritizing sorting, and even changing their layout style.Understand and make good use of these properties, which will make your website content management more flexible and efficient. ### One, set recommended properties for documents in the background To add recommended properties to a document, you first need to log in to the AnQi CMS backend management interface. 1. Enter the document editing page

2025-11-07

How does AnQiCMS achieve adaptive display for PC and mobile pages?

In today's era of coexistence of multiple devices, whether a website can present a good user experience on different screen sizes is directly related to its influence and commercial value.Whichever device the user accesses, whether it is a desktop computer, laptop, tablet, or smartphone, they all expect to see a page with clear layout and easy operation.AnQiCMS (AnQiCMS) is well aware of this core requirement and therefore integrated a variety of flexible adaptive display strategies from the outset to ensure that your website can be presented in **status** on any device.AnQi CMS provides three main website display modes

2025-11-07

How to ensure that the encoding of AnQiCMS template files is correct to avoid page garbled characters?

When using AnQiCMS to build a website, we may encounter abnormal display of pages, with garbled characters.This is usually due to incorrect encoding settings in the template file.Ensure that the template file uses the correct encoding is a key step to avoid such problems, ensure the normal operation of the website, and provide a good user experience.AnQiCMS as a modern content management system, its internal processing and recommendation standards tend to use UTF-8 encoding.UTF-8 is an international character encoding that can be compatible with the characters of most languages in the world, including Chinese

2025-11-07

How to implement Markdown format content rendering and display on the AnQiCMS web page correctly?

In the digital age, the efficiency of content creation and publishing is the key to the success of the website.Markdown as a lightweight markup language, with its concise and efficient features, is increasingly favored by content creators.AnQiCMS knows this need, providing excellent Markdown support to users, making content creation more convenient, while ensuring that the web page presents a beautiful and clear structure.

2025-11-07

How to get and display the previous and next article links of AnQiCMS articles?

In website content operation, guiding users to smoothly browse related content is a key link to improving user experience and website depth.After a user finishes reading an article, if they can immediately see links to related or sequential previous and next articles, it will undoubtedly encourage them to continue exploring. This not only helps to reduce the bounce rate but also effectively improves the website's PV (page views) and SEO performance.AnQiCMS (AnQiCMS) is an efficient content management system that provides a very convenient way to implement this function.In AnQi CMS

2025-11-07

How to use the pagination tags of AnQiCMS to control the display of list content?

In a content management system, how to effectively display a large amount of information without sacrificing user experience is always a question worth pondering.AnQiCMS provides a powerful and flexible pagination feature that allows website managers to finely control the display of list content, ensuring that the website is both beautiful and efficient.

2025-11-07