AnQiCMS (AnQiCMS) is an efficient and flexible content management system, with its powerful custom functions being an important treasure for website operators to improve efficiency and achieve personalized display. In daily content operations, we often encounter situations where we need to call back-end preset but non-standard field data, and{% diy %}The label is born for this. Then, what parameters should be set to accurately obtain the customized data from the background? Let's explore in depth.name参数究竟该如何设置,才能准确无误地获取到后台的自定义数据呢?让我们深入探讨一番。
Revelation{% diy %}Tag: Unlock the custom data treasure of the background
in the AnQi CMS template world,{% diy %}Tags play a very practical role: they allow us to flexibly retrieve those custom global data that do not belong to the system's predefined fields but are also wanted to be displayed on the front-end page.Imagine that you might want to display a company's annual slogan at the footer of the website or showcase a special event entry in the sidebar. This information is usually not bound to specific articles or products but rather as an integral part of the website.{% diy %}Tag is your powerful assistant
nameThe core secret of the parameter: accurate matching of background settings
Use correctly{% diy %}Understanding the tag is the most critical stepnameParameter setting rules. In short,nameThe value of the parameter must beExact matchIn the “Global Settings” or “Contact Information Settings” modules and others in the AnQi CMS background,The parameter name filled in when adding a custom parameter.
This means that when you create a custom data item in the background, the unique parameter name assigned to it is the front end{% diy %}in the tagnameThe expected parameter value. It is the bridge connecting backend data with the frontend template.
Data source: Where to set custom data in the backend?
In order to{% diy %}The label has data to be retrieved, and we first need to make the corresponding settings in the Anqi CMS backend. Usually, these global custom data are configured at the following two main locations:
Global settings custom parameters (recommended for website general information)Log in to the backend, find the "Global Settings" under the "Backend Settings" menu.In here, you will see an area for 'custom setting parameters'.Click the 'Add' button, and you can define new custom data items.
- Parameter name:This is the most important field! For example, you can fill in
CompanySlogan/SupportEmail/WeChatOfficialAccountAnd. This name will be used directly as{% diy %}TagnameThe value of the parameter. - Parameter value:Fill in the actual content of the parameter, for example
您的信任,我们守护!or[email protected]. - Note:For internal management, convenient for you to remember the purpose of the parameter.
- Parameter name:This is the most important field! For example, you can fill in
Custom parameters in the contact information settings (recommended for expanding corporate contact information)Similar to the "Global SettingsIf you need to add specific contact information in addition to the default contact information (such as phone number, address), such as Telegram account, Skype ID, etc., you can add it here.The setting logic is consistent with the custom parameters in the global settings.
Tip:When filling in the "parameter name", although AnQi CMS will automatically convert Chinese characters or space-containing parameter names to camel case in some cases (for example, "company slogan" may be converted toCompanyKouHaoBut to maintain the conciseness and readability of the template code, it is strongly recommended to use it directlyEnglish letters, numbers, and underscoresThe combination as "parameter name", and follow camel case naming conventions (such asCompanySlogan), so as to ensure the consistency and maintainability of front-end and back-end calls
Practical demonstration: Correct settingnameParameter
Let's look at how to operate with a specific example.
Scenario:You want to display the company's annual slogan at the footer of the website, which needs to be changeable in the background at any time.
Step 1: Set custom parameters in the background
- Log in to the AnQi CMS background.
- Navigate to "Background Settings" -> "Global Settings".
- In the "Custom Setting Parameters" area, click the "Add" button.
- In the popped-up form:
- Parameter name:Fill in
AnnualSlogan(Note that we used camel case naming here). - Parameter value:Fill in
科技赋能未来,智慧连接世界. - Note:Fill in
公司年度宣传口号.
- Parameter name:Fill in
- Click "OK" to save.
Second step: Use in the front-end template{% diy %}TagNow, you can use it in your template file (such aspartial/footer.htmlor any other location where you want to display the slogan{% diy %}tag to retrieve and display this annual slogan:
{# 直接输出自定义参数的值 #}
<p class="company-slogan">{% diy with name="AnnualSlogan" %}</p>
{# 或者,将值赋给一个变量再输出,方便进一步处理 #}
{% diy currentSlogan with name="AnnualSlogan" %}
<p class="company-slogan-dynamic">{{ currentSlogan }}</p>
Run the website, you will see this in the footer:
<p class="company-slogan">科技赋能未来,智慧连接世界</p>
<p class="company-slogan-dynamic">科技赋能未来,智慧连接世界</p>
See, as long asnameThe value of the parameter (AnnualSlogan) is exactly the same as the 'parameter name' set in the background,{% diy %}Labels can accurately extract the corresponding "parameter value" to the front-end page.
Why choose{% diy %}: Enhancement of operational efficiency
Master correctly{% diy %}Especially the usage of labels,nameParameter settings mean that:
- Centralized management:All non-content main custom information can be configured uniformly in the background, avoiding hard coding in the template and improving management efficiency.
- Flexible iteration: When this information needs to be updated, it only needs to be modified once in the background, and all calls to the site will be automatically synchronized without touching the code.
{% diy %}The places labeled will be automatically synchronized and updated without touching the code. - Reduce risk:Reduced the frequency of directly modifying template files, thereby reducing the risk of website problems caused by misoperation.
- Content and presentation are separated:Further realized the effective separation of website content and template performance, allowing content operations and template design to run in parallel without contradiction.
Frequently Asked Questions (FAQ)
Understand{% diy %}label'snameDuring the parameter setting process, you may encounter some questions. Below are several common questions and their answers:
1.{% diy %}Which types of data can the tag retrieve? For example, can it retrieve images or complex HTML fragments?
{% diy %}The tag is mainly used to retrieve the "custom parameters" stored in the background.Text stringData.This can be plain text, a URL link, a phrase, or even a short piece of HTML code.{% diy %}Labels will output these strings unchanged. In the template, you can combine<img>Labels can use the output image link, or use|safeThe filter safely renders HTML fragments. However, it does not directly support complex rich text editor content or file upload.
2. In the multi-site mode of AnQi CMS,{% diy %}How to label to get data from a specific site?
{% diy %}Tag supportsiteIdParameters. If you have enabled multi-site management in the background and want to get custom data from a non-current site, you can specifysiteIdTo implement. For example,{% diy with name="AnnualSlogan" siteId="2" %}Will try to get the site with ID 2.AnnualSloganParameter. If not specified,siteIdIt will default to getting the custom data of the current site.
3. If the backend custom parameter name contains Chinese or special characters, the front endnamehow should the parameter be filled in?
According to the design of AnQi CMS, when setting custom parameters in the background, it is recommended that the "parameter name" be a combination of letters and numbers. Although the system will automatically convert Chinese parameter names to camel case when processing custom parameters in "global settings" and "contact information settings" for template calls, to avoid unnecessary confusion and potential encoding issues,It is strongly recommended to use English camel case naming conventions when setting "parameter name"for exampleCompanySloganinstead of公司口号) in the front-endnameParameters can be directly matched, ensuring that the code is clear and the call is accurate. If the backend has already used Chinese as parameter names, you need to check where it is set specifically, and use the camel case naming form converted from it.nameFill in the parameter.
Hope this article can help you better understand and use Anqi CMS.{% diy %}Tags, make your website operation more skillful.