As an experienced security CMS website operation personnel, I fully understand the importance of flexible content management in improving user experience and operational efficiency.AnQi CMS with its powerful content model function allows us to easily customize and expand the website content structure according to specific business needs.Today, I will guide you to delve deeper into creating custom content model fields in AnQiCMS, such as adding an 'author' field to articles or detailed 'parameters' to products.
Understanding the content model and customized fields of AnQi CMS
In AnQi CMS, the content model is the basic framework for defining the type of website content, which determines what information your content can include.The system provides various preset models such as "Article Model" and "Product Model", but its true strength lies in its high degree of customization.This means that you can add, modify, or delete fields for these models based on the unique needs of your website, thereby achieving personalized content management.
Imagine if your website needs to publish technical articles, you may want to clearly indicate the "article author" and "publish date" for each article.Or if you are selling electronic products, you may need to add a series of detailed parameters such as 'processor model', 'memory size', 'screen size', and so on for each product.This personalized information outside the standard fields is exactly what is added and managed through 'custom fields'.By creating custom fields, you can ensure that each piece of content has the data structure most suitable to its characteristics, greatly improving the accuracy and usability of the content.
Create a custom content model field step by step
In the AnQiCMS backend, creating a custom field is an intuitive and user-friendly process.We will take 'article author' and 'product parameters' as examples to demonstrate how to operate in detail.
First, you need to log in to the AnQiCMS admin interface. Find and click on“Content Management”in the expanded submenu.“Content Model”Here will be listed all the content models currently available on your website, including system-built-in and custom models you may have created.
Select the model you want to add a custom field to. For example, if you want to add an author field to an article, click on the editing interface of the "article model";If you want to add parameters to the product, click to enter the editing interface of the 'Product Model'.At the bottom of the model editing page, you will see a name called“Content model custom field”area. Click on the area within.“Add field”Click the button to start configuring a new custom field.
Now, you will see a form that requires you to fill in some key information for your new field:
- Parameter name:This is the name displayed in the background content editing interface, it should be easy to understand and identify. For example, you can fill in "article author", "product color", or "CPU model".
- Call field:This is the unique identifier used to refer to the field in the template, it must consist of alphabetic characters.be sure to use concise and descriptive english lowercase letters.For example, the 'article author' can be set to
author,“Product color” can be set toproductColor,“CPU model” can be set tocpuModel. This field name is the core of the template tag call. - Field type:AnQiCMS provides various field types to adapt to different data formats:
- Single-line text:Suitable for short text input, such as article titles, author names.
- Number:Accepts only numeric input, suitable for prices, inventory, sizes, and other numerical values.
- Multi-line text:Suitable for long text content, such as product descriptions and detailed explanations.
- Single selection (Radio):Provide multiple preset options for the user to choose from.
- Multiple selection (Checkbox):Provide multiple preset options, the user can select multiple options at the same time.
- Select (Select):Display multiple options in the form of a dropdown menu, the user can only select one.
- When you select "Single Choice", "Multiple Choice", or "Dropdown Choice", you need to select the"Default Value"In the area, enter one option value per line, and the system will automatically parse it into a list of selectable options.
- Mandatory?:Tick this box, and the field must be filled in when creating or editing content in order to submit.
- Default:You can set a default initial value for the field. For selection type fields, the content entered here is your option list, one per line.
After completing the configuration of all fields, don't forget to click the“Save”button at the bottom of the page to make your changes effective.
apply custom fields in content creation
Once you add custom fields to the content model, these fields will immediately appear in the corresponding content editing interface. For example, if you add to theauthorfield, so when you publish a new article or edit an existing article, in the 'Other Parameters' collapse area, you will see an input box named 'Article Author' to enter the author information of the article. Similarly, if you define a 'Product Model' forproductColorandcpuModelThese fields will also appear in the editing interface when publishing or editing a product, waiting for you to fill in specific parameter values for the product.
Display custom fields in the front-end template
Presenting data stored in custom fields on the website's frontend is the final and most important step in the content management process.AnQiCMS provides flexible template tags, allowing you to easily display these customized information on the page.
1. Display a single custom field:If you want to directly retrieve the value of a specific custom field, such as "article author", you can usearchiveDetaillabel and specifynameThe parameter is the name of your "called field".
For example, display the article author:
<div>文章作者:{% archiveDetail with name="author" %}</div>
If your custom field is 'Product Model', its call field isproductModel:
<div>产品型号:{% archiveDetail with name="productModel" %}</div>
2. Loop to display all custom fields:For product parameters that may have multiple custom fields, you may wish to display them in a list format. At this time, you can usearchiveParamstags to get the current content.All custom fieldsAnd thenforLoop through and output.
Example code:
{% archiveParams params %}
<div>
{% for item in params %}
<div>
<span>{{item.Name}}:</span>
<span>{{item.Value}}</span>
</div>
{% endfor %}
</div>
{% endarchiveParams %}
Here, item.NameIt will display the parameter name you set in the background (for example, "CPU model"), whileitem.ValueThe value of this field will be displayed (for example, "Intel Core i7").
By following these steps, you can create, manage, and display various custom content model fields in AnQiCMS, thereby building high-quality website content that is more rich in structure and meets your business needs.Make full use of custom fields, which will be the key to improving your website's content management efficiency and user experience.
Frequently Asked Questions (FAQ)
Q1: Why can't I see the custom fields I created on the content editing page?
A1:Make sure you have selected the custom field associated with it when creating or editing contentContent modelbelowCategory. Custom fields are attached to specific content models and will only display in the "Other Parameters" area when editing content that belongs to that content model.For example, if you add custom fields to the 'Article Model' but you are editing content under a category that belongs to the 'Product Model', you will not see those custom fields of the article model.
Q2: How to determine if a custom field has a value before displaying it in the front-end template?
A2:You can use the conditional judgment tag of AnQiCMS.{% if %}Check if the value of the custom field is empty. For example, if your custom fieldauthormay be empty, you can handle it like this in the template:
{% archiveDetail authorName with name="author" %}
{% if authorName %}
<div>文章作者:{{ authorName }}</div>
{% else %}
<div>作者信息缺失</div>
{% endif %}
only whenauthorNameWhen there is a value, the author information will be displayed. For custom fields of array or list type (such as multi-select fields), you can also use{% if fieldName|length > 0 %}to determine if there is content.
Q3: Can the name of the custom field's 'reference field' contain Chinese or special characters?
A3:No. The name of the custom field's 'reference field' must useEnglish lettersThis is because the 'Call field' is used for data referencing in code and templates, similar to variable names in programming languages, and must follow specific naming conventions to ensure system stability and compatibility.If Chinese characters or special characters are used, it may cause the data to be saved incorrectly or not to be called normally in the template.