As a senior security CMS website operator, I know that content is the cornerstone of the website, and effective content management and personalized presentation are the key to attracting and retaining users.AnQi CMS, with its flexible content model, provides us with powerful customization capabilities, making content input no longer limited by predefined frameworks.Today, we will delve into how to customize the fields of the content model in Anqi CMS to achieve highly personalized content input.

The foundation of flexible content models: custom fields

In Anqi CMS, the content model is the core of defining the structure of specific types of content.The system provides the "article model" and "product model" by default, which include some common fields such as title, content, category, thumbnail, etc.However, in actual operation, our content needs are often more diverse and specific.For example, a product may require specific information such as 'brand', 'model', 'color options', 'stock quantity', etc.;A job posting may require unique fields such as "position salary", "work location", and "education requirements".

At this time, the custom field comes into being. It allows us to add exclusive data input items for each content model, ensuring that each type of content can be constructed in the most accurate and richest way possible.This greatly improves the efficiency of content management and also lays a solid foundation for personalized display on the front end, thus better meeting users' needs for the depth and accuracy of information.

Navigate to the content model management interface

To start customizing fields, we first need to enter the Anqi CMS backend management interface.In the left navigation bar, find and click "Content Management", then select "Content Model".This will list all the content models currently in the system, including built-in models and any custom models we may have already created.

We can choose to modify an existing model, such as a "product model", to add specific fields, or create a brand new content model from scratch to define all its properties.No matter which way, the core operation is to configure the model fields.

Detailed steps for customizing content models and fields

On the content model editing or new page, there are several core areas that we need to pay attention to.

The first is the basic information setting of the model:

  • Model nameThis is the Chinese name displayed in the background and breadcrumb navigation of the model, which should intuitively reflect the content type of the model, such as "Tour route" or "Solution".
  • Model table nameThis is the table name stored in the database for model data, it must be in English lowercase letters. This field is unique and usually not recommended to be changed arbitrarily once set.
  • URL aliasFor use in static rule definition{module}The call, it will be reflected in the URL path of the front-end page, and it is recommended to use lowercase letters in English.
  • Title NameThis setting is very user-friendly, it will replace the common prompt text of "Document Title" when publishing documents.For example, if this is a 'product model', we can set it as 'product name' to make it clear for content editors.

The key area for implementing personalized content input is - 'Custom fields of content model'.Here we can freely add dedicated fields to the current model based on business requirements.

Click "Add field", a form will pop up to configure the detailed properties of each custom field:

  • Parameter NameThis is the Chinese name of the field displayed on the backend editing interface for operators, such as 'Product Price', 'Applicable Industry', 'Article Source', etc.Clear parameter names help content editors accurately understand the field usage.
  • Field invocationThis is the actual field name stored in the database, as well as the unique identifier for data calls in the front-end template. It must use letters, such asprice/industry/source. It is recommended to use camelCase or underscore naming conventions and maintain consistency.
  • Field type: AnQi CMS provides various field types to adapt to different data formats:
    • Single-line text: Suitable for short text input, such as brand names, product models, author names, etc., the length limit is usually within 250 characters.
    • Number:Designed for numeric data, such as price, inventory quantity, reading volume, etc., ensure that the format of the input content is correct.
    • Multi-line textFor scenarios that require input of long text, such as product descriptions, event introductions, and solution overviews.
    • Single choice: Multiple options can be set, but the user can only select one, for example, "Product Status" (new, popular, discontinued).The value is set through the "Default Value" area below, one option per line.
    • Multiple selections: Multiple options can be set, but the user can select one or more options, such as "Product Features" (waterproof, dustproof, shockproof).The option value setting is the same as single selection.
    • Drop-down selectionProvide a dropdown menu for users to select one option, suitable for scenarios with many options and space-saving needs, such as 'Product Color' (Red, Blue, Green, Black).The option value setting method is the same as single selection.
  • Mandatory?: You can specify whether this field is required to be filled in when the content is published. If it is set as required, the system will perform verification when submitted.
  • Default valueSet an initial value for the field. This area is used to enter all available options for fields of single-choice, multiple-choice, and dropdown types. Each option is entered on a separate line.If the field has a default value and is left blank during content editing, the default value will be automatically displayed when the front-end is called.

After configuring all custom fields, save the content model. These new fields will take effect immediately.

Experience personalized input when publishing content.

After the custom field is configured and saved, enter the 'Content Management' module again, select 'Add Document' or edit an existing document.In the document editing interface, when we select a content model category that belongs to a custom field that has been added, these new fields will be displayed in the 'Other Parameters' collapsible area.

Content editors can now accurately fill in product parameters, event details, or other specific information based on these personalized input boxes.This structured input method not only ensures the consistency and integrity of the data, but also greatly reduces the complexity of content entry, ensuring the quality of the content.

Flexibly call custom fields in the front-end template

The value of the custom field ultimately manifests in the dynamic display on the front-end page.AnQi CMS provides powerful and flexible template tags, allowing us to easily call these custom data in the page.

To call the value of a single custom field, we can use{% archiveDetail with name="自定义调用字段" %}tags. For example, if we define a call field for the product model asmaterial(Material), we can call it like this on the product details page:<div>产品材质:{% archiveDetail with name="material" %}</div>.

If we need to dynamically traverse and display all custom fields and their values, especially for product parameter lists and similar scenarios, we can use{% archiveParams params %}Label. It will return an array object containing all custom fields, we can iterate through them.forLoop to display one by one:

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

In this way, even if the future content model adds new custom fields, the front-end template does not need to be significantly modified, it only needs to republish the content to dynamically display, greatly improving the maintainability and scalability of the template.

Summary

The content model custom field function of AnQi CMS is a direct embodiment of its 'flexible content model' project advantage.It broke the rigid structure of traditional CMS in content structure, giving us the ability to customize the content input interface according to specific business needs.By carefully planning and configuring custom fields, we can achieve more accurate data management, a more efficient content creation process, and a richer variety of front-end content display, ultimately providing users with a more personalized and valuable website experience.


Frequently Asked Questions

Can the custom field be applied to all content models?

Yes, Anqi CMS allows you to add custom fields to the built-in "article model" and "product model", and also create new content models and define exclusive fields for them.Each custom field belongs to a specific content model and does not confuse.

How can you dynamically determine if a custom field exists in a template and display it?

In the front-end template, you can use{% archiveParams params with sorted=false %}Get an unordered map object and then useifstatements to combineinAn operator is used to determine whether a custom field (through its "calling field") exists. For example,{% if 'author' in params %} ... {% endif %}You can determine if there is a custom field named "author". If it exists, then proceed through{{params.author.Value}}Get its value.

If I modify the 'call field' of the custom field, will it affect the existing content?

Modifying the "call field" (i.e., the database field name) of a custom field is a sensitive operation.In most cases, if this field already has data, direct modification will cause the original data to be inaccessible through the new field name, resulting in data loss or display errors.It is recommended to make a data backup before making changes and to avoid modifying the 'call field' that is already in use.If indeed a modification is required, it may be necessary to perform data migration at the database level, mapping data from old fields to new fields, which usually requires the assistance of technical personnel.