The AnQi CMS, known for its efficiency and customization, is an enterprise-level content management system that undoubtedly serves as a good helper for content operators and website developers with its powerful template tag functions.In the daily operation of websites, we often encounter the need to quickly adjust some global and site-level configuration information, such as the company's slogan, a link to a specific event, or a temporary announcement text, etc. This information does not require complex classification and models like article content, but is more flexible than hard-coded in templates.{% diy %}The tag and its underlying custom parameter management mechanism is particularly important.
This article will delve into how to create and manage these in the AnQiCMS background.{% diy %}The custom parameters used for labels, which are seamlessly applied to the website front-end, helping you better utilize the flexibility of AnQiCMS, achieving quick response and efficient operation.
Understanding{% diy %}Label: Your customized information hub
In the template system of AnQiCMS,{% diy %}Label plays the role of a 'universal information box'. Unlike{% system %}The tag is used to obtain the global system information (such as website name, Logo, filing number), and is different from{% contact %}The tag is used to obtain contact information (such as phone, email, address),{% diy %}Tags are specifically used to call functions you have in the backgroundCustom text or link information with global or semi-global properties that you have added.
Imagine if your website needs to display a banner saying 'Summer Promotion Ongoing!' during a special period, or if you want to add a social media link in the footer that is not part of the preset contact information, use{% diy %}Label combined with custom parameters can easily be implemented without modifying any template code file, greatly enhancing operational efficiency.
Create and manage custom parameters in the AnQiCMS backend in English
To make{% diy %}The label has content that can be "pulled", and we first need to define these custom parameters in the AnQiCMS backend. This process is very intuitive.
You will find that in the AnQiCMS background,全局功能设置and联系方式设置these two modules both provide the function of "custom setting parameters". This means,{% diy %}The label can flexibly call the custom parameters you define in these two areas.This provides certain convenience for logical classification of parameters, for example, custom links related to contact can be placed in "Contact Settings", and other more general information can be placed in "Global Function Settings".
Let us take the example of adding a custom parameter for a company vision (Company Mission) in the "Global Feature Settings":
Navigate to the settings pageFirst, log in to your AnQiCMS back-end management interface. Find and click in the left navigation bar.
系统设置then select全局功能设置.Locate the custom parameter area.In the "Global Feature Settings" page, scroll down, and you will see an area named "Custom Setting Parameters". This is where we add personalized configurations.
Add a new custom parameterClick
添加自定义参数Button, a form will pop up or expand at this time, allowing you to fill in parameter information.- Parameter nameThis is the most critical field, which determines the name used when calling this parameter in the template. It is recommended to use English letters and follow camel case naming conventions (such as
CompanyMission/HolidayNoticeThis can maintain the clarity of naming and is convenient for calling in templates. Please note that this parameter name should be unique throughout the entire website to avoid confusion. - parameter value
- [en] Note
- Parameter nameThis is the most critical field, which determines the name used when calling this parameter in the template. It is recommended to use English letters and follow camel case naming conventions (such as
Save Changes:Fill in after completion, click
保存button, your custom parameters have been successfully added and take effect.
By the same method, you can add custom parameters related to contact information in the "Contact Information Settings", such as a specific WhatsApp group link or an online customer service time description.
In the front-end template usage{% diy %}tags
After creating the custom parameters, the next step is to skillfully use them in the website template{% diy %}标签来显示这些信息了。AnQiCMS的模板引擎采用了类似Django模板引擎的语法,让变量和标签的使用变得非常直观。
{% diy %}The basic usage of the label is similar to{% system %}and{% contact %}, bynamespecifying the parameter name to be called.
For example, if we want to display the 'company vision' set just now in the header or footer of the website:
{# 直接输出自定义参数的值 #}
<p>我们的愿景:{% diy with name="CompanyMission" %}</p>
{# 将自定义参数的值赋值给一个变量,再进行输出和处理 #}
{% diy missionText with name="CompanyMission" %}
{% if missionText %}
<p>我们的愿景是:{{ missionText }}</p>
{% else %}
<p>暂无公司愿景信息。</p>
{% endif %}
In the above code snippet:
{% diy with name="CompanyMission" %}It will directly output the namedCompanyMissionThe custom parameter value.{% diy missionText with name="CompanyMission" %}If soCompanyMissionThe value of the parameter is assigned to a namedmissionTextThe template variable. The advantage of doing this is that you can make further logical judgments (such as{% if missionText %}String processing (if AnQiCMS filter supports) or combined with other content on the page, making the template more dynamic and robust.
Please note,{% diy %}Label supports all parameters, for examplesiteIdAlso applies to the invocation of custom parameters. If you have a need to manage multiple sites, you can specifysiteIdto get the custom parameters of a specific site.
Through this method, you can easily push various operational information, announcements, promotional slogans, etc., from the background to the website front-end, achieving fast content updates and flexible management without touching a single line of code. This is exactly the powerful convenience brought by AnQiCMS as an enterprise-level content management system.
Common Questions (FAQ)
1.{% diy %}Tags and{% system %}or{% contact %}What is the difference between tags?
{% system %}and{% contact %}Tags are used to call the AnQiCMS systemPredefinedGlobal information (such as website name, Logo, filing number) and contact information (such as phone, email). However,{% diy %}Label is used to call the "Global Feature Settings" or "Contact Information Settings" you set in the backgroundCustom parameter areaAutomatically created, personalized, non-predefined parameters. Simply put, the former are built-in items, and the latter are your extended items.
2. Can I use{% diy %}Label an article or product with custom fields?Cannot.{% diy %}Tags are designed for site-wide or global custom parameters. If you need toSpecific articles, products, or other content modelsAdd custom fields (such as, the "author" field of articles, the "color" option of products), you should内容管理-内容模型Defined in the definition. These model fields will be displayed when editing specific articles or products, and{% archiveDetail %}or{% archiveParams %}are called using these tags, not{% diy %}.
3. If I call{% diy %}Parameter does not exist, what will happen?If{% diy %}The parameter name tried to be called in the label is not defined in the background. AnQiCMS template engine usually returns an empty value or does not output any content, rather than throwing an error and causing the page to crash. To enhance the robustness of the template, you can use conditional judgments (such as{% if yourDiyParameter %}Check for the existence or value of the parameter to avoid displaying unnecessary or missing information.