As an experienced CMS website operation personnel, I know that content is the cornerstone of the website, and effective management and personalized presentation of content are the key to attracting and retaining users.AutoCMS provides us with powerful customization capabilities with its flexible content model, making content input no longer limited by predefined frameworks.Today, we will delve into how to customize the fields of content models in the AnQi CMS, thereby achieving highly personalized content input.

The foundation of flexible content models: custom fields

In the AnQi CMS, the content model is the core for defining the structure of specific types of content.System default provides "Article Model" and "Product Model", which include some common fields such as title, content, category, thumbnail, etc.However, in actual operation, our content requirements 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', 'education requirements', etc.

The custom field is therefore born.It allows us to add dedicated data input fields for each content model, ensuring that each type of content can be built in the most precise and rich way.This greatly improves the efficiency of content management and lays a solid foundation for personalized front-end display, thereby better meeting users' needs for information depth and accuracy.

Navigate to the content model management interface

We can choose to modify an existing model, such as a 'Product Model', to add specific fields, or create a completely new content model from scratch, defining all its properties.Whether it is in any way, the core operation is to configure the model fields.

Customize content model and field detailed steps

When editing or creating a new content model page, there are several core areas we need to pay attention to.

Firstly, the basic information settings 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 "travel route" or "solution.
  • Model table nameThis is the table name stored in the database for the model data, it must be in lowercase English letters. This field is unique, and it is usually not recommended to change it arbitrarily once set.
  • URL aliasEnglish: Used in the pseudo-static rule of{module}The call, it will be reflected in the URL path of the front-end page, it is also recommended to use English lowercase letters.
  • Title nameThis setting is very user-friendly, it will replace the general prompt text 'Document Title' when publishing documents.For example, if this is a "product model", we can set it to "product name" to make it clear to the content editor.

The next step is to implement the key area for personalized content input - 'Content Model Custom Fields'.Here we can freely add dedicated fields to the current model according to business requirements.

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

  • Parameter nameThis is the Chinese name displayed on the background editing interface to the operator, for example, 'Product Price', 'Applicable Industry', 'Article Source', etc.Clear parameter names help content editors accurately understand the field usage.
  • Call fieldThis is the actual field name stored in the database, as well as the unique identifier for data calls in the front-end template. Make sure to use letters, for example,price/industry/source。Suggest using camel case or underscore naming conventions and maintain consistency.
  • field type:The CMS provides various field types to accommodate different data formats:
    • Single Line Text:Applicable to short text input, such as brand names, product models, author names, etc., usually limited to 250 characters.
    • NumberEnglish: Designed specifically for numeric data, such as prices, inventory quantities, reading counts, etc., to ensure the correct format of input content.
    • Multi-line text:Applicable to scenarios that require input of long text, such as product descriptions, event introductions, and solution overviews.
    • Single selection:Allow multiple options to be set, but the user can only select one, for example, "Product Status" (new, best-selling, discontinued).The option value is set through the "Default Value" area below, one option per line.
    • Multiple selection:Similarly, 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 method is the same as single selection.
    • Drop-down selection:Provide a dropdown menu for users to select an item, suitable for scenarios with many options and the need to save page space, such as 'Product Color' (Red, Blue, Green, Black).The way to set the option value is the same as single choice.
  • Is required:Can specify whether this field is required to be filled in when the content is published. If set to required, the system will perform validation upon submission.
  • Default valueEnglish: Set an initial value for the field.For single-choice, multiple-choice, and dropdown selection fields, this area is used to enter all available options, with one option per 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.

Complete the configuration of all custom fields and save the content model. These new fields will take effect immediately.

Experience personalized input when publishing content.

When the custom field configuration is completed and saved, enter the "Content ManagementIn 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 using 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.

Flexible calling of custom fields in front-end templates

The value of the custom field is ultimately reflected in the dynamic display on the front-end page.The auto 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 a product modelmaterial(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 scenarios such as product parameter lists, we can use{% archiveParams params %}Label. It returns an array object containing all custom fields, and we can iterate over them to display each one:forLoop to display them one by one:

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

This way, even if the content model adds new custom fields in the future, the front-end template does not need to be significantly modified. It only needs to republish the content to dynamically display it, which greatly enhances the maintainability and extensibility of the template.

Summary

The content model custom field feature of Anqi CMS is a direct reflection of its 'flexible content model' project advantage.It breaks the rigid structure of traditional CMS in content structure, giving us the ability to customize content input interfaces according to specific business needs.By carefully planning and configuring custom fields, we can achieve more precise data management, a more efficient content creation process, and a richer variety of frontend content display, ultimately providing users with more personalized and valuable website experiences.


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 to create new content models and define exclusive fields for them.Each custom field belongs to a specific content model and will not be confused.

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

In the front-end template,{% archiveParams params with sorted=false %}Get an unordered map object and then useifSentence combinationinoperator to judge whether a custom field (through its "calling field") exists. For example,{% if 'author' in params %} ... {% endif %}Can determine if there is a custom field named "author". If it exists,{{params.author.Value}}to 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., database field name) of the custom field is a sensitive operation.In most cases, if this field already has data, directly modifying it will cause the original data to be inaccessible through the new field name, resulting in data loss or display errors.Suggest to make a data backup before modification, and try to avoid modifying the 'Call field' that has been put into use.If indeed a modification is required, it may be necessary to perform a database-level data migration, mapping the data of old fields to new fields, which usually requires the assistance of technical personnel.