As an experienced security CMS website operation person, I fully understand the importance of flexible content management in improving user experience and operational efficiency.The Anqi CMS boasts powerful content model features, allowing us to easily customize and extend the website content structure according to specific business needs.Today, I will guide you to delve deeper into how to create custom content model fields in AnQiCMS, such as adding an 'author' field for articles or detailed 'parameters' for products.
Understanding the CMS content model and custom fields
In the Auto CMS, the content model is the basic framework that defines the type of website content, which determines what information your content can include.System provides a variety of preset models such as 'Article Model' and 'Product Model', but the real strength lies in its high degree of customization.This means you can add, modify, or delete fields for these models according to the unique needs of your website to achieve personalized content management.
Imagine if your website needs to publish technical articles, you may want each article to clearly indicate the "article author" and "publish date".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.These personalized information outside the standard fields is exactly added and managed through the "custom fields".By creating custom fields, you can ensure that each piece of content has the data structure that best fits its characteristics, greatly improving the accuracy and usability of the content.
Step by step to create custom content model fields
In AnQiCMS backend, creating custom fields is an intuitive and user-friendly process.We will take 'Article Author' and 'Product Parameters' as examples to demonstrate how to operate in detail.
Firstly, you need to log in to the AnQiCMS backend management interface. Find and click in the left navigation menu.“Content Management”In the expanded submenu, select.“Content Model”。Here you can list all the content models currently available on your website, including both built-in and any 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 to enter the editing interface of the 'Article Model'; if you want to add parameters to a product, click to enter the editing interface of the 'Product Model'.“Content Model Custom Fields”area. Click the area within it.“Add Field”Press the button, and you can 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 of the field, which should be easy to understand and identify. For example, you can fill in 'article author', 'product color', or 'CPU model'.
- Field call:This is the unique identifier used when referencing this field in the template, and it must consist of alphabetic characters.please make sure to use concise and descriptive english lowercase letters.
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 accommodate different data formats:
- Single-line text:Applicable to short text input, such as article titles, author names.
- Numbers:Accepts numeric input only, suitable for values such as prices, inventory, dimensions, etc.
- Multi-line text:Applicable to longer text content, such as product descriptions and detailed explanations.
- Single selection (Radio):Provide multiple preset options, and users can only choose one.
- Multiple Selection (Checkbox):Provide multiple preset options, users can select multiple at the same time.
- Dropdown selection (Select):Display multiple options in the form of a dropdown menu, users can only select one.
- When selecting 'Single Choice', 'Multiple Choice', or 'Dropdown Selection', you need to fill in thedefault valueIn the area, enter an 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 during content creation or editing to submit.
- Default value: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.
Complete the configuration of all fields, don't forget to click the“Save”button to make your changes take effect.
apply custom fields in content creation
Once you add custom fields to the content model, these fields will immediately display in the corresponding content editing interface. For example, if you add custom fields to the "Article Model".author字段,那么当您发布新文章或编辑现有文章时,在“其他参数”的折叠区域内,您会看到一个名为“文章作者”的输入框,供您填写文章的作者信息。同样地,如果您为“产品模型”定义了productColorandcpuModelThese fields will also appear in the edit 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 the data stored in the custom field on the website 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 get the value of a specific custom field, such as “Article Author”, you can usearchiveDetaila tag to 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', the field name isproductModel:
<div>产品型号:{% archiveDetail with name="productModel" %}</div>
2. Display all custom fields in a loop:For situations where product parameters may have multiple custom fields, you may wish to display them uniformly in a list. At this time, you can usearchiveParamstags to get the current contentAll custom fields, and proceed throughforLoop 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"),item.ValueThen the value filled in this field will be displayed (for example, “Intel Core i7”).
By following these steps, you will be able to create, manage, and display various custom content model fields in AnQiCMS, thereby constructing high-quality website content that is richer in structure and more in line with your business needs.Reasonably utilizing custom fields will be the key to improving your website's content management efficiency and user experience.
Common Questions and Answers (FAQ)
Q1: I created custom fields, why can't I see them in the content editing page?
A1:Make sure you have selected the custom fields associated with it when creating or editing content.Content ModelunderCategory.Custom fields are attached to specific content models, and they will only display in the 'Other Parameters' area when editing content that belongs to that content model.For example, if you add a custom field to the "article model" but you are editing content under the category of "product model", you will not see those custom fields of the article model.
Q2: How to determine if a custom field has a value in the front-end template before displaying it?
A2:You can use the condition 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 in the template like this:
{% archiveDetail authorName with name="author" %}
{% if authorName %}
<div>文章作者:{{ authorName }}</div>
{% else %}
<div>作者信息缺失</div>
{% endif %}
thenauthorNameThe author information will be displayed when there is a value. 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 any content.
Q3: Can the name of the 'invoked field' of the custom field contain Chinese characters or special characters?
A3:No. The name of the 'invoked field' of the custom field must useEnglish letters.This is because the "call field" is used as an identifier for data references in code and templates, similar to variable names in programming languages. It needs to 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.