How to configure unique display fields for different content models in AnQiCMS to adapt to personalized content display?

In the Anqi CMS, in order to meet the diverse display needs of website content, configuring unique display fields for different content models is a crucial feature.This ability allows us to flexibly customize the structure of articles, products, events, or any other type of content based on specific business requirements, thereby providing a highly personalized content display experience.

Understand content model: the basis of personalized display

One of the core strengths of AnQiCMS is its 'flexible content model'.It allows us to break through the fixed "article" or "page" limitations of traditional content management systems and customize content types according to actual business scenarios.Imagine that your website not only needs to publish ordinary news articles, but also needs to display complex product details, registration pages for events, and even professional industry reports.Each content type has its unique properties, such as products needing price, stock, and SKU; events needing start time, end time, and maximum number of registrants; and news articles may require author, source, and other information.

The content model is a structured tool provided by AnQiCMS, which defines all the fields contained in a certain type of content.The system is pre-installed with 'Article Model' and 'Product Model', but the real power lies in the ability to create new models as needed or modify existing models to equip them with unique field sets.

Configure unique display fields: the key to custom content models

The first step in personalized content display is to deeply customize your content model and add exclusive display fields.

First, you need to enter the management background of AnQiCMS, find "Content ManagementHere is a list of all existing content models, you can choose to edit an existing model, or click 'Add Custom Model' to create a new content type.

Whether it is editing or adding, the core lies in the "Content Model Custom Fields" area of the model detail page.Here, you can define any number of dedicated fields for the current model.

  1. Parameter nameThis is the display name of the field in Chinese, convenient for you to identify when publishing content in the background, such as 'Product Price', 'Event Location', etc.
  2. Call fieldThis is the unique identifier of the field, used for template calls and database storage. Please make sure to use alphabets, for exampleproductPrice/eventLocation. This name needs to be unique and consistent throughout the system.
  3. field type:AnQiCMS provides various field types to meet different data format requirements:
    • Single Line Text:Suitable for short text input, such as titles, contact names.
    • Number:Ensure that the input content is purely numeric, such as price, quantity.
    • Multi-line text:Suitable for long text descriptions, such as product introductions, event details.
    • Single selection:Provide preset options, users can only select one, such as 'Gender', 'Product Color'.
    • Multiple selection:Provide preset options, users can select multiple items, such as "Product Function Tags".
    • Drop-down selection
  4. Is required:You can decide whether to fill in this field when publishing content based on the importance of the content.
  5. Default value:Set an initial value for the field. For selection fields, this is where you define the option list.

Complete field configuration and save the model.When you enter the "Content Management" "Publish Document" page, select the category associated with your custom model, and you will find that these newly defined fields are clearly presented in the "Other Parameters" section, waiting for you to fill in specific data for each piece of content.

Display custom fields in the frontend template: convert data into visual

Just configuring fields and data in the background is not enough to achieve personalized display; the key is how to extract and present the data of these custom fields in the website's front-end template.AnQiCMS template engine supports Django-like syntax, which makes data calls very flexible and powerful.

How many common ways are there to display custom fields in a template:

  1. Directly call the specific custom fieldIf you know the 'Field Name' of the custom field, you can use it directlyarchiveDetailTag to get and display its value. For example, if your product model has a custom field namedproductPrice, you can call it like this in the product details page template:

    <div>产品价格:{% archiveDetail with name="productPrice" %}</div>
    

    For custom fields of multi-image upload type, for example,arcimagesyou may need to display in a loop:

    {% archiveDetail arcimages with name="arcimages" %}
    <ul class="product-gallery">
      {% for img in arcimages %}
      <li><img src="{{img}}" alt="产品图片" /></li>
      {% endfor %}
    </ul>
    
  2. Loop through all custom fields.In some cases, you may want to dynamically list all custom fields and their values without needing to know their names beforehand.archiveParamsLabels are very useful. It returns an array containing all custom fields, you can iterate through this array to display:

    {% archiveParams params %}
    <div class="product-specs">
        {% for item in params %}
        <div>
            <span>{{item.Name}}:</span> <!-- 显示字段的中文名称 -->
            <span>{{item.Value}}</span> <!-- 显示字段的值 -->
        </div>
        {% endfor %}
    </div>
    

    If you want to exclude certain custom fields that are not needed to be displayed on the front-end, you can add conditional judgment in the loop, for example:

    {% archiveParams params %}
    <div class="product-specs">
        {% for item in params %}
        {% if item.Name != '内部备注' and item.Name != '管理代码' %}
        <div>
            <span>{{item.Name}}:</span>
            <span>{{item.Value}}</span>
        </div>
        {% endif %}
        {% endfor %}
    </div>
    
  3. Combine the filtering function to implement advanced display: 除了在详情页展示,您还可以利用自定义字段在列表页实现复杂的筛选功能。AnQiCMS的EnglisharchiveFiltersarchiveListThe label will automatically query and display matching content based on these conditions, greatly enhancing the interactivity and user experience of the website.

**Practical Tips and Considerations

  • Naming conventions:Select a concise and meaningful English name for the 'called field', which is convenient for template developers to understand and call.
  • Field type matches:According to the actual data content, choose the most suitable field type, for example, selecting the 'number' type for price can avoid input errors and facilitate subsequent numerical calculations.
  • Plan firstBefore creating content models and custom fields, it is best to plan all the content properties you want to display to avoid frequent modifications later.
  • Test verification:Complete the configuration and template call of custom fields, and be sure to perform thorough testing on different pages and scenarios to ensure that the content is displayed correctly and beautifully.
  • Focus on SEOAlthough custom fields are mainly used for content display, their content itself can also be indexed by search engines.Ensure that the text content in the custom field is valuable and helpful in enhancing page relevance.

Through the flexible content model and custom field functions of AnQiCMS, you can easily achieve highly personalized content management and display.Whether it is to build a complex e-commerce platform or operate a media website with rich content, these tools will give you a helping hand to make your website content more attractive and more in line with user needs.


Common Questions (FAQ)

**1. Why do I add custom fields in the content model but they are not displayed when publishing articles?