When building and operating a website, we often need to display more information than just the title and body, such as product models, colors, inventory, or the author, source, and publishing platform of the article.AnQiCMS knows the importance of personalized content display, therefore, it provides a highly flexible custom parameter field function, making website content management and frontend display both powerful and convenient.Next, let's delve deeper together to fully utilize this feature in AnQiCMS, making your website content dynamic.
First step: Define your content structure - Create custom parameter fields
In AnQiCMS, all content is organized based on the 'content model'.Whether it is an article, product, or other custom type, you can tailor a unique field structure for it.This is like building a dedicated 'skeleton' for your content, ensuring that each type of content can carry its unique information.
To create or modify custom parameter fields, you need to go to the 'Content Management' section of AnQiCMS backend and find 'Content Model'.Here, the "article model" and "product model" are provided by default, and you can also add custom models according to your business needs.
Select a content model to enter the editing interface, you will see a section named "Content Model Custom Fields.Here, you can click "Add Field" to add new custom parameters to the model.
- Parameter name:This is the name displayed to the administrator on the backend management interface for this custom field, for example "Product ModelIt should be an intuitive and understandable description in Chinese.
- Field call:This field name is used when calling this parameter in the front-end template, and must be in English letters, and it is recommended to use camelCase naming method (such as
productModel/authorName/stockQuantityIn subsequent template development, we will mainly use this 'call field' to retrieve data. - Field Type:AnQiCMS supports various field types to meet different data entry requirements, such as:
- Single-line text:Suitable for brief text information, such as model, brand.
- Numbers:Ensure only numbers are entered, suitable for prices, inventory, etc.
- Multi-line text:Suitable for longer descriptions, such as product features, author bios.
- Single choice, multiple choice, dropdown selection:These selection fields are very suitable for preset options, such as colors (red, blue, green), sizes (S, M, L), and regions, which greatly improve the standardization and accuracy of data entry.You can set these options one per line in the "default value".
- Mandatory:According to the importance of the field, you can choose whether it is a required item when publishing content.
- Default value:Set a default value for the field, which can be automatically filled in when content is published, reducing manual input.
Complete these settings and save your content model. Now, you have successfully defined a new data structure for your content type.
第二步:fill in your data - add custom information to articles or products
With a custom field structure in place, the next step is to enter this data for actual articles or products.When you go to "Content Management" under "Publish Document
Expand this collapse box, and you will see those custom fields defined just now in the content model, clearly arranged according to the 'parameter name' you set.You can easily assign unique attribute values to each piece of content, whether it is entering text, selecting numbers, or making a choice from a dropdown menu, it is very intuitive.
If some fields are left blank, and you have set a default value for it in the content model, then when displayed on the front end, the system will automatically assign the default value to the field.For articles containing images or automatically extracted summaries, AnQiCMS will also intelligently process them to help you save time.
第三步:dynamically display content - call custom parameters in the front-end template
Data entry is complete, the most exciting part is how to dynamically display this custom information on the front end of the website.AnQiCMS uses the Django template engine syntax, with its concise and powerful tag and variable calling methods, making this process efficient and flexible.
Display custom parameters in the template, mainly the following common methods:
1. Directly call specific custom fields in the detail page
If you are on the article or product detail page (usually)detail.htmlor{模型table}/detail.html)中,想要显示某个特定的自定义参数,比如文章的“作者”或产品的“型号”,可以直接通过archive对象访问其属性:
`twig {# 假设你的自定义字段“调用字段”是 author #}