AnQi CMS is a high-efficiency, customizable enterprise-level content management system, whose powerful template tag function is undoubtedly a good helper for content operators and website developers.In daily website operations, we often encounter the need to quickly adjust some global, site-level configuration information, such as company slogans, links to specific events, or temporary announcement texts, etc. These pieces of information do not require complex categorization and models like article content, but are more flexible than hardcoded in templates.This is provided by Anqi CMS{% diy %}The tag and its underlying custom parameter management mechanism is particularly important.

This article will delve into how to create and manage these supplies in the AnQiCMS backend.{% diy %}Label custom parameters and seamlessly apply them to the website front-end, helping you better utilize the flexibility of AnQiCMS to achieve quick response and efficient operation.

Understanding{% diy %}Label: Your customized information center

In the AnQiCMS template system,{% diy %}Labels play the role of a 'universal information box.' Unlike{% system %}The tag is used to retrieve system preset global information (such as website name, Logo, filing number), and is different from{% contact %}The tag is used to retrieve contact information (such as phone, email, address),{% diy %}Labels used to call the backendCustom text or links with global or semi-global properties 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 that does not belong to the preset contact information, use{% diy %}Label配合custom parameters can easily be implemented without modifying any template code files, greatly improving operational efficiency.

Create and manage custom parameters in the AnQiCMS backend

To make{% diy %}Tags can be retrieved, and we first need to define these custom parameters in the AnQiCMS background. This process is very intuitive.

You will find that in the AnQiCMS backend,全局功能设置and联系方式设置these modules both provide the function of "custom setting parameters". This means,{% diy %}Labels can flexibly call the custom parameters you define in these two areas.This provides certain convenience for the logical classification of parameters, for example, custom links related to contact can be placed in the "Contact Settings", while other more general information can be placed in the "Global Function Settings".

Let us take the example of adding a custom parameter for a company vision in the "Global Feature Settings".

  1. Navigate to the settings pageFirst, log in to your AnQiCMS admin interface. In the left navigation bar, find and click系统设置and then select全局功能设置.

  2. Locate the custom parameter areaIn the "Global Feature Settings" page, scroll down and you will see a section named "Custom Setting Parameters". This is where we add personalized configurations.

  3. Add a new custom parameterClick添加自定义参数Button, at this time, a form will pop up or expand, for 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 letters and follow camelCase naming conventions (such asCompanyMission/HolidayNoticeThis keeps the naming clarity, and it is convenient to call it in the template. Please note that this parameter name should be unique throughout the website to avoid confusion.
    • Parameter valueHere is the actual content you want to store, which can be plain text, HTML code snippets, URL links, and so on.For example, we can fill in 'leading industry innovation, empowering enterprise development'.
    • NoteThis is an optional but strongly recommended field. Here, you can briefly describe the purpose of this parameter, such as 'the core vision displayed to the public by the company', which is very helpful for team collaboration and future parameter maintenance.
  4. Save Changes: Click after filling in保存Button, your custom parameters have been successfully added and taken effect.

In the same way, 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.

Use in the front-end template{% diy %}Tag

After creating a custom parameter, the next step is to skillfully use it in the website template{% diy %}Tags are used to display this information. AnQiCMS template engine adopts the syntax similar to Django template engine, making the use of variables and tags very intuitive.

{% diy %}The basic usage of the tag is similar to{% system %}and{% contact %}By usingnameThe attribute specifies the parameter name to be called.

For example, 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 name ofCompanyMissionCustom parameter value.
  • {% diy missionText with name="CompanyMission" %}Then the value ofCompanyMissionthe 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 filters are supported)or used in conjunction with other page content, making the template more dynamic and robust.

Please note,{% diy %}All parameters supported by the tag, for examplesiteIdAlso applies to the invocation of custom parameters, if you need to manage multiple sites, you can specifysiteIdto retrieve the custom parameters of a specific site.

In this way, you can easily push various operational information, announcements, promotional slogans, etc., from the background to the front end of the website, achieving fast content updates and flexible management without touching a single line of code, which is the powerful convenience brought by AnQiCMS as an enterprise-level content management system.


Frequently Asked Questions (FAQ)

1.{% diy %}with the tag and{% system %}or{% contact %}What is the difference between tags? {% system %}and{% contact %}Tags are used to call the AnQiCMS systemPredefinedThe global information (such as website name, Logo, filing number) and contact information (such as phone, email) and...{% diy %}Tags are specifically used to call the "Global Function Settings" or "Contact Information Settings" in the backgroundCustom parameter areaParameters manually created, personalized, and non-presets. Simply put, the former is built-in items, and the latter are your extended items.

2. Can I use{% diy %}Add custom fields to specific articles or products?No.{% diy %}Tags are designed for site-wide or global custom parameters. If you need to add toa specific article, product, or other content modelAdd custom fields (such as the 'author' field of an article, the 'color' option of a product), you should内容管理-u003e内容模型Define these model fields. These model fields will be displayed when editing specific articles or products and are called through{% archiveDetail %}or{% archiveParams %}tags instead of{% diy %}.

3. If I call{% diy %}What will happen if the parameter does not exist?If{% diy %}The parameter name tried to be called 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 that causes the page to crash. To enhance the robustness of the template, you can use conditional judgment in the template (such as{% if yourDiyParameter %}Check for parameter existence or values to avoid displaying unnecessary or missing information.