One of the core advantages of AnQiCMS in content management is its flexible and customizable content model.This allows us to no longer be limited by fixed content structures, and be able to create personalized content types that meet the actual operational needs of the website.No matter if you are publishing technical articles, displaying product details, or managing event information, customized content model fields can help you accurately construct the content structure you need, and ultimately flexibly display it on the website front end.
Below, let's take a look at how to customize the content model fields in AnQiCMS and flexibly call their content in the template.
1. Understanding the value of custom content models
AnQiCMS's custom content model mechanism allows you to add exclusive fields for different content types (such as "articlesThese fields are like the 'DNA' of content, defining all the information that each type of content should contain, thus achieving structured management of content.This makes content entry clearer and more efficient, and also provides great flexibility for front-end display. You can call and display the content of each field accurately according to your needs.
Define custom fields in AnQiCMS backend
The settings for custom fields are performed under the "Content Model" in the "Content Management" module.AnQiCMS comes with two basic models, 'Article Model' and 'Product Model'. You can directly edit them or create a new custom model.
Enter content model management:Log in to the AnQiCMS backend, navigate to 'Content Management' -> 'Content Model'. Here, you will see a list of all existing content models.
Edit or create a model:Select a model you want to add a custom field to (for example, 'Article Model' or 'Product Model'), click the 'Edit' button next to it.If you want to start from scratch, you can also click 'Add New Model' to create a completely new content model.
Add custom field:On the model editing page, you will see the "custom field" area of the content model.This is where you define your personalized field.
- Parameter name:This is the name displayed in the background management interface, which is also a Chinese description convenient for you to understand the field usage, such as 'article author', 'product model', 'service features', etc.
- Call field:This is the unique identifier actually used to call this field in the template,Must use English lettersIt is recommended to use all lowercase or camel case, for example,
author/modelNumber/features. This name is very important, and it will be used to retrieve data in the template later. - Field type:AnQiCMS provides various field types to meet different data input requirements:
- Single-line text:Applicable to short text information, such as author name, product model.
- Number:Only numbers are allowed, such as price, stock quantity.
- Multi-line text:Applicable to longer text, such as product introduction, service description.
- Single choice/Multiple choice/Dropdown choice:Suitable for scenarios where preset options are provided for selection, such as product color (single selection), service scope (multiple selection). These options need to be filled in one per line in the "default value
- Image group/file group:Suitable for uploading multiple images or files.
- Mandatory?:Tick this box, the field will become a required field when publishing content.
- Default:You can set a default value for the field. If it is a selection type field, it is used here to fill in all available options, one per line.
After adding and configuring the field, be sure to click the "Save" button at the bottom of the page to make the changes take effect.
3. Fill in the custom fields when publishing content.
After you have defined the custom field, go back to the 'Content Management' module, select 'Add New Document' or edit an existing document, and choose a category associated with the model you just modified or created.For example, if you add a field in the "Product Model", then when publishing a category under the "Product Model", these custom fields will automatically appear in the "Other Parameters" collapse area of the document editing page, waiting for you to fill in the corresponding content.This greatly simplifies the content editing process, ensuring the integrity and standardization of the content.
Four, flexibly call custom field content in the template
The power of custom fields lies in their ability to be accurately captured and displayed by AnQiCMS template tags. AnQiCMS's template engine is similar to Django syntax, using{{变量}}Output content,{% 标签 %}Control logic.
1. Call the custom field of a single content on the detail page
On the document detail page (for example{模型table}/detail.htmlWe usually need to display all the details of the current document.
Directly call the known field name:If you know the name of the custom field's 'call field', you can use it directly.
archiveDetailLabel to get its value. For example, you added a field namedauthorThe field (called field) "article author" (parameter name):<p>文章作者:{% archiveDetail with name="author" %}</p>Or perhaps added to the "product model"
productPriceField:<p>产品价格:{{ archive.productPrice }} 元</p> {# 简单字段也可以直接通过archive.调用字段名访问 #}Loop through all custom fields:Sometimes, you may want to display all the additional information of the document without specifying each one.
archiveParamsLabels can help you traverse all the custom fields set.{% archiveParams params %} <div class="custom-fields"> {% for item in params %} <p>{{ item.Name }}:{{ item.Value }}</p> {% endfor %} </div> {% endarchiveParams %}Here,
item.NameIt is the "parameter name" you set in the background (such as "article author"),item.ValueThe actual value you enter when publishing content.Handle special field types (such as image groups, multiple choices):For image groups, multiple choice types, and other fields that return arrays or lists, you need to use loops to display. For example, you define a named `