In website operation, we often encounter the need to add some personalized information to the content or the global website outside of the standard fields.This information may include the distinctive features of a website, product parameters, specific attributes of articles, and even multi-channel contact information, etc.AnQiCMS (AnQiCMS) understands the importance of this flexibility, therefore it provides a powerful custom parameter configuration function, allowing you to easily define the required data in the background and flexibly call and display it in the front-end template.
Next, we will delve into how to configure these custom parameters in the Anqi CMS backend, as well as how to巧妙ly apply them in your website front-end template.
The first part: Configure custom parameters in the Anqi CMS backend
The configuration of Anqi CMS custom parameters is mainly divided into two categories: custom parameters for global website settings and contact information, as well as custom fields for different content models (such as articles, products).
1. Configure global and contact information customization parameters
The global information and contact details of a website often need to be adjusted according to business changes, and it is obviously not an efficient solution to modify the template code each time.The AnQi CMS allows you to directly add these general custom parameters in the background.
Operation path:Log in to the Anqi CMS backend, you can find "Backend Settings" in the left menu.
- Global settings:Enter the "Global Function Settings" page, scroll to the bottom to see the "Custom Setting Parameters" area.
- Contact Information:Enter the "Contact Information Settings" page, and there is also a "Custom Setting Parameters" area at the bottom.
Configuration method:Click the "Add Parameter" button, and you will see three input boxes:
- Parameter name:This is the unique identifier you use when calling the template.Suggest using English or pinyin, such as “HelpUrl”, “WhatsApp”.The system will automatically convert it to camel case.
- Parameter value:The actual content of this parameter, such as a help page URL or your WhatsApp account.
- Note:Used to describe the purpose of this parameter, convenient for future management and understanding.
In this way, you can easily add global information such as company honors, special service links, language switch prompts for multilingual websites, or more social media contact information other than phone and email.
2. Configure custom fields of content models
For different types of content such as articles, products, and activities, the information structure they need to display is often quite different.For example, a product introduction may require attributes such as 'color', 'size', 'material', etc., while a news article may require 'author', 'source', 'reading time', etc.The AnQi CMS content model custom field function is specifically designed to meet such needs.
Operation path:In Anqi CMS backend, select the "Content Management" menu, then click the "Content Model".Here is listed all the content models on your website, such as the default "article model" and "product model".
Configuration method:
- Edit or add models:You can choose to edit an existing model, or click 'Add Model' to create a new content type.
- Add custom field:Enter the model editing page, find the "Content Model Custom Field" area. Click the "Add Field" button, and a field configuration interface will pop up:
- Parameter name:This is the Chinese name of the field that the background editor sees when publishing or modifying content, such as 'Article Source', 'Product Color'.
- Call field:This is the unique English identifier used to retrieve the value of this field in the front-end template.Ensure the name is concise and descriptive, for example, "source", "color".This field name will be stored directly as a database field.
- Field type:AnQi CMS provides various field types to adapt to different data formats:
- Single-line text:Suitable for short text input, such as author names, article sources.
- Number:Only allows input of numbers, such as prices, inventory.
- Multi-line text:Text suitable for long content, such as a brief introduction of product details.
- Single choice/Multiple choice/Dropdown choice:These types are suitable for scenarios where preset options need to be chosen, such as product colors (red, blue, black), and house types (residential, commercial).
- Mandatory?:Determine whether this field is required based on business needs.
- Default:Set an initial value for the field. For selection types, this is used to define all possible options, with one option per line.
After completing the configuration of custom fields, when you add or edit documents under the corresponding model in "Content Management
The second part: Flexible display calls in the front-end template
After configuring the background parameters, the next step is to display this data to the visitor in the front-end template.The Anqi CMS template engine syntax is similar to Django, data calls can be realized through concise tags.
1. Call the custom parameters of global and contact information
For custom parameters added in the "Global Function Settings" and "Contact Information Settings", Anqi CMS provides specific tags for calling:
Global custom parameters:Use
{% system %}Label. If you add a parameter named "HelpUrl" (help page link) in the background global settings, its value ishttps://www.yourdomain.com/helpyou can call it like this in the template:<a href="{% system with name="HelpUrl" %}">访问帮助中心</a>Custom contact information parameters:Use
{% contact %}Label. If you add a parameter named "WhatsApp" (WhatsApp account) in the background contact settings, its value is+1234567890How to call:<span>我们的WhatsApp:{% contact with name="WhatsApp" %}</span>
2. Call the custom field of the content model
The custom fields of the content model are usually used on the document detail page or list page, Anqi CMS provides various flexible calling methods.
Directly call the specified custom field:On the document details page, if you define a "author" field for the article model, you can directly
archive.authoror{% archiveDetail with name="author" %}to retrieve and display:<p>作者:{{ archive.author }}</p> {# 或者,如果您想在当前文档之外指定其他文档ID #} <p>文章来源:{% archiveDetail with name="source" id="10" %}</p>For categories, single pages, tags, and similar things, there are also similar
categoryDetail/pageDetail/tagDetailtags to directly call their custom fields. For example, the 'Banner' field of the category:<img src="{% categoryDetail with name="Banner" %}" alt="分类Banner">Loop to display all custom fields:Sometimes, you may want to dynamically display all the custom parameters of an item in an area (such as a product) without having to call them individually.
{% archiveParams %}The tag is designed for this purpose. It will return an array containing all custom field names and values, which you can useforLoop through and display:<h3>产品参数详情</h3> <ul> {% archiveParams params %} {% for item in params %} <li> <span>{{item.Name}}:</span> {# 这是后台设置的“参数名”(中文显示) #} <span>{{item.Value}}</span> {# 这是该参数的实际值 #} </li> {% endfor %} {% endarchiveParams %} </ul>This