In the powerful feature matrix of AnQi CMS, the content model and custom fields are undoubtedly one of its core highlights.It provides the website with great flexibility, allowing operators to build various types of content structures such as articles, products, services, and cases according to actual business needs.However, for operators who are not familiar with template development, it is often a challenge to dynamically and elegantly display these rich and diverse custom fields on the website front-end, especially when it comes to showing both their 'parameter names' and 'actual values'.

Today, as an experienced website operations expert, I will guide you to deeply analyze the method of dynamically displaying all custom fields under the current content model in Anqi CMS template, helping you to perfectly present the flexible configuration of the backend to the users.

Understanding the content model and customized fields of AnQi CMS

First, let's briefly review the concept of custom fields in AnQi CMS.In AnQi CMS backend, you can enter the 'Content Management' under the 'Content Model' feature.Here, you can create or edit different content models (such as 'article model', 'product model').Each content model can add a series of "custom content model fields".

When you add a custom field, you need to define several key pieces of information:

  • Parameter Name (Name):This is used in the backend management interface and frontend template.DisplayGive to the user or as a label name, for example 'Article Source', 'Product Model'.
  • Field Name (FieldName):This is stored in the database and displayed in the front-end templateTechnical callThe unique identifier of this field, usually a combination of lowercase English letters, such assource/model_number.
  • Field type:Determines the form of the input data for the field, such as single-line text, multi-line text, number, radio, checkbox, etc.
  • Whether mandatory, default value, etc.:Further standardize the behavior of the field.

The value of dynamically displaying these fields is that, regardless of how many custom fields you add to the content model or how you modify them in the future, the template can intelligently traverse and display them without needing to modify the template code each time.

The core idea of dynamically obtaining custom fields in the template

The AnQi CMS template engine (similar to Django or Blade syntax) provides powerful tags for retrieving and processing data.For the need to dynamically display custom fields, we no longer need to hard code the 'call field' names for each field one by one.The core idea is to use a special tag that can return a list of all custom fields under the current content (such as articles, products), and then we traverse the list to extract the 'parameter name' and 'actual value' of each field.

Here, our main character isarchiveParams.

UsearchiveParamsTraversal of custom fields by tag

archiveParamsThe tag is designed to obtain custom parameters for the current document (or specified document).It can provide all the custom fields configured for the document in a traversable array object to the template.

archiveParamsBasic usage of tags

Usually, you will be in the document detail page (for example{模型table}/detail.htmlThis tag is used in the structure. Its basic format is as follows:

"twig {% archiveParams params with sorted=true %}"

{% for item in params %}
    <div>
        <span>{{ item.Name }}:</span>
        <span>{{ item.Value }}</span>
    </div>
{% end