During the operation of a website, we often encounter such needs: the standard content fields (such as title, content, publish time) can no longer meet the needs of personalized display.For example, a product detail page may need to display "manufacturing date
AnQiCMS as a flexible enterprise-level content management system fully considers these custom requirements.It provides powerful features, allowing you to easily create these personalized parameters in the background and safely and conveniently call them to display in the front-end template.
Let's explore step by step how to implement these custom features in AnQiCMS.
I. Set custom parameters in the AnQiCMS backend.
AnQiCMS provides two main ways of custom parameters to meet different application scenarios: custom fields for specific content models (such as articles, products) and global or contact information custom parameters.
1. Content model custom field: Add exclusive properties for specific content types
When you need to add unique information to the content of articles, products, or other custom models, the content model custom fields are the ideal choice.For example, add 'color', 'size', 'material', and other attributes to the 'product' model, or add 'work location', 'salary range', and 'education requirements' to the 'recruitment' model, and so on.
To set these fields, you can go to the back end.Content Managementand then clickContent model. Here, you can choose to edit an existing model (such as 'Article Model' or 'Product Model'), or create a new content model as needed.
After entering the model editing page, you will see a namedCustom fields for content modelarea. Here, you can add new fields:
- Parameter NameThis is the Chinese name displayed on the backend interface for the administrator to understand its purpose, such as 'article author', 'product color'.
- Field invocation:This is a very critical item!This field name will be the unique identifier you will use when calling this parameter in the front-end template. It is strongly recommended that you use concise English lowercase letters or camel case naming (such as
author/productColor). Once set and saved, this field name is usually not recommended to be changed easily, as it directly affects the normal display of the front-end template. - Field type: AnQiCMS provides various field types to adapt to different data formats:
- Single-line text: Suitable for short text input, such as author names, product models.
- NumberEnsure that the input is purely numeric, such as inventory quantity, price.
- Multi-line textSuitable for longer descriptions, such as product features, article summaries.
- Single choice/Multiple selections/Drop-down selectionThese types allow you to preset options, and users can only choose from them.Their option values are entered one per line in the "default value" area, and the system will automatically parse them as selectable items.
- Mandatory?If this field is crucial for the completeness of the content, it can be made mandatory.
- Default valueProvide an initial value for the field. For selection fields, here are all the options available.
After completing the custom field settings, when you enter againContent ManagementofPublish documentPage, and when you select a category that belongs to the content model, you will see these custom fields that you just added in the "Other Parameters" collapse box, waiting for you to fill in specific values for each piece of content.
2. Global/Contact Information Custom Parameters: Configure General Website Information
Some parameters are not bound to a specific article or product, but are universal for the entire site, such as additional social media links for the website, special announcement text, or a guide link to a specific page. AnQiCMS is inGlobal SettingsandContact information settingsThe "Custom settings parameters" feature is provided to meet such needs.
- Global Settings: Find it in the background navigationBackend settings, clickGlobal Settings. Scroll to the bottom of the page, and you will seeCustom settings parametersArea. Here, you can add for example
HelpUrl(help page link),AnnouncementText(website announcement) and other custom parameters. - Contact information settings: Also inBackend settingsclickContact information settings. In addition to the preset contact information on this page, you can also add additional contact information, such asCustom settings parametersadding extra contact methods like
WhatsAppaccounts, specific customer service staff numbers, etc.
Enter custom parameters at these two positions:
- Parameter Name: It is also the identifier called in the template, it is recommended to use English, for example
HelpUrl/WhatsAppAccount. The system will automatically convert it to camel case. - Parameter valueThis is the specific content of the parameter, such as a URL link, some text.
- NoteOptional, used to describe the purpose of the parameter for future management.
These global or contact information custom parameters can be called in any template of the entire website, providing a unified and flexible information display for the website.
Second, call the custom parameter display in the front-end template
In AnQiCMS, the front-end template uses a syntax similar to the Django template engine. Variables are enclosed in double curly braces{{变量}}Whereas logical control tags (such as conditional judgment, loop) use single curly braces and percent signs{% 标签 %}.
Understood, we can easily call the custom parameters set in the background in the template.
1. Call the custom field of the content model
For custom fields bound to content models such as articles, products, etc., AnQiCMS provides several ways to call them:
Directly by variable name (for the current detail page or list loop)
If you are on the document detail page(
archive.html) and know the name of the custom field's "call field" (for exampleauthor),you can use it directly{{archive.author}}to display its value.<p>作者:{{ archive.author }}</p> <p>文章来源:{{ archive.source }}</p>Similarly, if you are in a
archiveListloop (such as displaying a list of articles), you can also access these custom fields through the loop variableitemto access these custom fields:{% archiveList archives with type="list" limit="10" %} {% for item in archives %} <div class="article-item"> <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3> <p>作者:{{ item.author }}</p> {# 假设你有一个名为 'author' 的自定义字段 #} <p>发布日期:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</p> </div> {% endfor %} {% endarchiveList %}For the current document detail page, you can also use
archiveDetailtags to get the value of a single custom field:<div>产品颜色:{% archiveDetail with name="productColor" %}</div>By
archiveParamstags to loop through all custom fields (suitable for dynamic display)If you are unsure about the custom fields of a content model, or want to dynamically display all custom fields and their values (for example, listing all specifications in a product detail page),
archiveParamsTags are very convenient.This tag will return an array containing all custom fields, you can go through
forthem in a loop.”`twig {% archiveDetail currentArchive with name=“Id” %} {# Get the current document ID, specify id if not on the detail page #}
<h3>详细参数</h3> {% archiveParams params with id=currentArchive %} {# 使用当前文档ID获取参数,或省略id在详情页自动获取 #} <ul> {% for item in params %} <li> <span>{{ item.Name }}:</span> {# 'Name'