As a senior CMS website operation personnel, I am well aware that a content management system not only needs to meet the basic content publishing requirements but also must have high flexibility and scalability to adapt to the constantly changing operation strategies.In AnQiCMS, in addition to the various parameters built into the system, we often need to add some custom global parameters according to specific business scenarios and website design, so that they can be flexibly called in templates and achieve personalized content display.

Add custom global parameters in AnQiCMS backend

AnQiCMS provides an intuitive and simple way to extend global configuration, allowing operators to customize website-level parameters without modifying the core code.These custom parameters can be centrally managed and referenced as needed on any page template of the website.

To add custom global parameters, you need to log in to the AnQiCMS backend management interface and navigate to the 'Global Function Settings' or 'Contact Information Settings' module under 'Backend Settings'.At the bottom of these two modules, you will find an area named "Custom Setting Parameters".

Here, you can click the "Add" button to add new custom parameters. Each custom parameter includes three core fields:

  • Parameter NameThis is the unique identifier used to call this parameter in the template. It is recommended to use lowercase English letters and follow camelCase naming conventions (for examplecustomTitle,companySlogan),以保持代码的整洁性和可读性。系统会自动将输入的字母转换为驼峰命名。
  • 参数值 (Parameter Value)This is the content you want the parameter to actually output. It can be any text, URL, number, or other information.
  • RemarkThis field will not be displayed in the front-end template. Its purpose is to help you better understand and manage the use of these custom parameters.An clear remark can significantly improve team collaboration efficiency and future maintenance convenience.

For example, if you add a feature named in the "Global Feature Settings"HelpUrlThe parameter valuehttps://en.anqicms.com/help,and add a note “Link to help document”, then this custom parameter has been successfully added and can be used throughout the site. Similarly, if you add a contact information setting namedWhatsAppThe parameter, used to display WhatsApp contact information, is also operated in this way.

Call custom parameters in AnQiCMS template

Once the custom parameters are set up in the background, they can be called through specific tags in the website template.The AnQiCMS template engine supports Django template engine syntax, making parameter calls very intuitive.

For custom parameters added in the "Global Function Settings", we mainly usesystemThe tag is used to make calls. This tag is specifically used to retrieve system-level configuration information, including built-in parameters and your custom global parameters.

For example, to call the previous one added in the "Global Function Settings"HelpUrlCustom parameters can be used with the following template code:

{# 直接输出自定义参数的值 #}
<a href="{% system with name="HelpUrl" %}" target="_blank">帮助中心</a>

{# 将自定义参数赋值给一个变量后输出,适用于更复杂的逻辑处理 #}
{% system helpLink with name="HelpUrl" %}
<p>访问我们的帮助页面:<a href="{{helpLink}}" target="_blank">{{helpLink}}</a></p>

Similarly, for custom parameters added in the "Contact Information Settings", such asWhatsAppUsecontacttags to call.contactTags are used to retrieve all configurations related to the website's contact information.

The template code for calling WhatsApp custom parameters is as follows:

{# 直接输出自定义的WhatsApp联系方式 #}
<p>WhatsApp联系方式:{% contact with name="WhatsApp" %}</p>

{# 将自定义参数赋值给一个变量后输出 #}
{% contact whatsappNumber with name="WhatsApp" %}
<p>紧急联系请拨打:{{whatsappNumber}}</p>

Extract text, links, and other information that needs to be frequently updated or centrally managed on the website and configure them as custom parameters in this way.This not only reduces the complexity of template maintenance, but also improves the efficiency of website content updates and operational flexibility.When it is necessary to modify some global information, you only need to modify the parameter value once in the background, without having to delve into multiple template files to search and modify them.

Frequently Asked Questions

Q1: Why doesn't the front-end page update immediately after modifying the custom parameters?

A1: AnQiCMS in order to improve website performance, will use cache to store configuration information.After you modify the custom parameters in the background, you may need to clear the system cache to make the changes take effect immediately.You can find the "Update Cache" feature in the AnQiCMS backend, click to execute it.

Q2: Can I enter HTML code in the 'Parameter Value' of the custom parameter?

A2: Yes, you can.Custom parameter's 'Parameter value' field supports input of HTML code.<script>or<a>),You may need to use|safeFilter to inform the template engine not to escape it, to ensure that the HTML code is rendered correctly. For example:{{customHtmlVar|safe}}.

Q3: How should I handle different custom parameters to be displayed based on different pages or content models?

A3: The global custom parameters are used to maintain consistent information throughout the entire site.If your requirement is to display different parameters for specific pages, categories, or content models, it is more recommended to use AnQiCMS's custom fields for content models, category custom fields, or single-page custom fields.These fields allow you to add unique parameters for specific content objects, and call them in the corresponding detail page or list page template, thus achieving more refined content control.