As an experienced senior CMS website operation personnel, I know that a content management system not only needs to meet the basic content publishing needs but also needs to have high flexibility and scalability to adapt to the constantly changing operation strategies.In AnQiCMS, in addition to the various built-in parameters, we often need to add some custom global parameters according to specific business scenarios and website design, so that we can flexibly call them 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 in 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 contains three core fields:

  • Parameter Name (Parameter Name)This is the unique identifier used to call this parameter in the template. It is recommended to use lowercase letters and follow camelCase naming conventions (such ascustomTitle,companySlogan),to maintain code neatness and readability. The system will automatically convert the input letters to camel case.
  • Parameter ValueThis is the content you want the parameter to actually output. It can be any text, URL, number, or other information.
  • Remark (Remark)This 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.A clear note can significantly improve team collaboration efficiency and future maintenance convenience.

For example, if you add a namedHelpUrlThe parameter value ishttps://en.anqicms.com/helpAnd add a note "link to the help document", then this custom parameter has been successfully added and can be used throughout the site. Similarly, if you add a named contact information settingWhatsAppThe parameter is used to display WhatsApp contact information, and it operates in the same way.

Call custom parameters in the 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 call. 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 previously added in the "Global Function Settings"HelpUrlYou can use the following template code for custom parameters:

{# 直接输出自定义参数的值 #}
<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", for exampleWhatsAppThen usecontactCall the tag.contactTags are used to retrieve all configurations related to the website's contact information.

Invoke the template code example for WhatsApp custom parameters:

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

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

In this way, you can extract the text, links, and other information that need to be frequently updated or centrally managed on the website, and configure them as custom parameters.This not only reduces the complexity of template maintenance, but also improves the efficiency of website content updates and operational flexibility.When you need to modify a global piece of 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 one by one.

Frequently Asked Questions

Q1: Why does the front-end page not update immediately after modifying the custom parameters?

A1: AnQiCMS to improve website performance, it 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.

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

A2: Yes, you can. The 'Parameter Value' field of the custom parameter supports input of HTML code.But when calling the template, if the HTML code contains tags that need to be explained (such as<script>or<a>),You may need to use|safeA filter that tells the template engine not to escape it, to ensure that HTML code can be rendered correctly. For example:{{customHtmlVar|safe}}.

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

A3: 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, then it is recommended to use the AnQiCMS content model custom fields, category custom fields, or single page custom fields feature.These fields allow you to add unique parameters for specific content objects, and call them in their corresponding detail page or list page templates, thus realizing more refined content control.