In AnQi CMS, the flexibility and maintainability of the website are one of its core advantages.Content operators and developers often need to dynamically adjust some global information of the website, such as the company name, contact phone number, and even some marketing activity links, without modifying the template code.These are the global parameters customized in the background, which are the key to meeting this requirement.

Today, let's take a deep dive into how to easily obtain and display these custom global parameters configured in the Anqi CMS template.

Why do we need global parameters?

Imagine if your website needs to change the company name or phone number, and this information is hardcoded in dozens of template files. Then, each modification will be a time-consuming and error-prone task.The appearance of global parameters is to solve such problems.It allows you to manage these common information uniformly in the website backend. When the information changes, you only need to modify it once in the backend, and all pages that call this parameter will be automatically updated, greatly improving the operation efficiency and maintainability of the website.

How to set global parameters on the backend?

The AutoCMS provides several places for you to set global parameters, the most commonly used being the 'Global Features Settings' under 'Background Settings' and 'Contact Information Settings'.

  1. [en] Global function settingsIn 'Background Settings' -> 'Global Feature Settings', in addition to system-built-in parameters such as website name, website logo, filing number, etc., you can also add more exclusive global parameters through 'Custom Settings Parameters'.

    • Click 'Add Parameter', enter 'Parameter Name' (this is the unique identifier used when calling the template, recommended to use English, which the system will automatically convert to camelCase), enter 'Parameter Value' (the content you want to display), and add 'Remarks' for future management. For example, you can add a parameter namedHelpUrlThe parameter, with the value ofhttps://en.anqicms.com/help.
  2. Contact information settingsSimilarly, the "Background Settings" -u003e "Contact Information Settings" also supports custom parameters. This is usually used to manage contact information such as phone, email, WeChat, etc.

    • You can add parameters likeWhatsAppand enter your WhatsApp contact number.

These settings completed, these custom parameters are just like the built-in system parameters and can be flexibly called in the front-end template.

Obtain global parameters in the template

The template engine of AnQi CMS supports tag syntax similar to Django, you can retrieve global parameters of the backend settings through specific tags. The core tags mainly includesystem/contactanddiy.

1. Get system-level global parameters (systemLabel)

systemLabel is specifically used to get parameters configured in the "Global Function Settings", whether built-in or custom.

Basic usage: {% system 变量名称 with name="字段名称" %}

Here,字段名称This is the parameter name you set in the background.

  • Directly output the built-in parameters:If you want to display the filing number at the bottom of the page, you can write it like this:

    <p><a href="https://beian.miit.gov.cn/" rel="nofollow" target="_blank">{% system with name="SiteIcp" %}</a></p>
    

    Here,SiteIcpThis is the备案号 parameter name built into Safe CMS.

  • Output a custom parameter and assign it to a variable:Assuming you have defined a named in the global settings of the background.HelpUrlThe custom parameter, you can access and use it in the template like this:

    {% system helpPageUrl with name="HelpUrl" %}
    <a href="{{ helpPageUrl }}">查看帮助文档</a>
    

    PasswithThe keyword, you can assign the value of the parameter you get tohelpPageUrlthis variable, and then use it multiple times in the template.

  • Get the current year:In addition,systemThe tag also has a helper function, which is to get the current year, which is very useful in copyright information:

    <p>&copy; {% now "2006" %} {{ siteName }}. All Rights Reserved.</p>
    

    Here{% now "2006" %}It will display the current year.

2. Get contact information global parameters (contactLabel)

contactTags used to get parameters configured in "Contact Information Settings", including built-in contact methods and custom parameters.

Basic usage: {% contact 变量名称 with name="字段名称" %}

  • Directly output the built-in contact phone number:

    <span>联系电话:{% contact with name="Cellphone" %}</span>
    

    Here,CellphoneIs the built-in contact phone parameter name of Anqi CMS.

  • Output the custom WhatsApp parameter:Suppose you added a contact name in the background contact information settings.WhatsAppA custom parameter named:

    {% contact whatsappNumber with name="WhatsApp" %}
    <a href="https://wa.me/{{ whatsappNumber }}" target="_blank">通过WhatsApp联系我们</a>
    

3. Get the general custom content (diyLabel)

ExceptsystemandcontactTags, in addition to the tags, Anqi CMS also provides a more generaldiyLabel, used to retrieve custom content information that may be defined at other positions in the background. Although the document does not directly provide background settingsdiyThe entry of the parameter, but if your system has been developed twice, or if additional global parameters are defined in some content modelsdiyThe tags will be your good helper.

Basic usage: {% diy 变量名称 with name="字段名称" %}

  • Output general custom parameters:Assuming you have a namedAuthorcustom global parameter, you can usediytag to get:
    
    {% diy websiteAuthor with name="Author" %}
    <span>网站作者:{{ websiteAuthor }}</span>
    

Useful tips and precautions

  • Parameter name case sensitivity:When defining parameter names in the background, although it is recommended to use English, there is no need to worry about case sensitivity, because AnQi CMS will automatically match it when calling the template.
  • Multi-site support:If you have used the multi-site function of Anqi CMS and want to call the global parameters of a specific site, you cansystem/contact/diyadd tags insiteIdparameters, such as{% system with name="SiteName" siteId="2" %}where,"2"is the ID of the target site.
  • HTML content processing:If your custom parameter value contains HTML code (such as copyright information output from a rich text editor), please make sure to use it in the template output.|safeFilter to prevent HTML from being escaped and not displayed properly.
    
    {% system siteCopyright with name="SiteCopyright" %}
    <div>{{ siteCopyright|safe }}</div>
    

Through these flexible global parameter calling methods, you can make your company CMS website template more dynamic and easy to manage, thus more efficiently carry out content updates and website operations.

Common Questions (FAQ)

  1. 问:If my custom parameters contain HTML code, how should I display it correctly? Answer:When your custom parameter value is in HTML format, you need to use it in the template output.|safeFilter. For example, if you define a parameter "website introduction" containing HTML in the backgroundSiteIntro, you should write it like this in the template: {% system siteIntroContent with name="SiteIntro" %}{{ siteIntroContent|safe }}So, the HTML code will be parsed and displayed normally by the browser.

  2. Q: Why is there no content displayed when calling the custom parameter set in the background in the template? Answer:This usually has several reasons. First, please check if the 'parameter name' matches the one in the template.nameThe attribute value matches completely. Next, confirm whether you have added the parameter in the correct backend setting area (such as "Global Feature Settings" or "Contact Information Settings") and used the corresponding template tag (systemorcontact)。Finally, if it is in a multi-site environment, confirm whether the correct one has been specified.siteId. Sometimes, clearing system cache (find the option 'Update Cache' in the background menu) may also resolve display issues.

  3. 问:In a multi-site environment, how do you call global parameters of other sites? 答::In the multi-site environment of AnQi CMS, you can access the global parameters of other sites bysystem/contactanddiytag.siteIdParameter to specify which site's global parameter to call. For example, if you want to get the global parameter for the site with ID2, you can write the site name like this:{% system otherSiteName with name="SiteName" siteId="2" %}. This way, you can call global parameters across sites.