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 without modifying the template code, such as the company name, contact number, and even some marketing campaign links.These are the background-defined global parameters that are the key to realizing 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 hard-coded 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 in the website background uniformly, when the information changes, you only need to modify it once in the background, and all pages that call this parameter will automatically update, greatly improving the operation efficiency and maintainability of the website.

How to set global parameters on the back end?

AnQi CMS provides several places for you to set global parameters, the most commonly used ones are the 'Global Function Settings' under 'Background Settings' and 'Contact Information Settings'.

  1. Global feature settingsIn the "background settings" -> "global function settings", in addition to the system built-in parameters such as website name, website logo, filing number, etc., you can also add more exclusive global parameters through "custom parameter settings".

    • Click "Add Parameter", enter the "Parameter Name" (this is the unique identifier used when calling the template, it is recommended to use English, which will be automatically converted to camel case by the system), enter the "Parameter Value" (the content you want to display), and add a "Remark" for future management. For example, you can add a namedHelpUrlThe parameter value,https://en.anqicms.com/help.
  2. Contact information settingsSimilarly, the "Background Settings" -> "Contact Information Settings" also supports custom parameters. It is usually used to manage phone numbers, email addresses, WeChat, and other contact information.

    • You can add such asWhatsAppcustom parameters and enter your WhatsApp contact number.

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

Get global parameters in the template.

The AnQi CMS template engine supports tag syntax similar to Django, you can use specific tags to retrieve global parameters set in the background. The core tags mainly includesystem/contactanddiy.

1. Obtain system-level global parameters (systemtags)

systemThe tag is specifically used to obtain parameters configured in the "Global Function Settings", whether built-in or custom.

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

here,字段名称It is the parameter name 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 directly:

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

    here,SiteIcpIs an AnQi CMS built-in record number parameter name.

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

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

    BywithThe 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:Furthermore,systemThe tag also has an auxiliary function, which is to get the current year, and this 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. Retrieve contact information global parameters (contacttags)

contactTag used to retrieve parameters configured in the "Contact Information Settings", including built-in contact methods and custom parameters you define.

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

  • Directly output the built-in contact phone number:

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

    here,CellphoneIt is the built-in contact phone parameter name of AnQi CMS.

  • Output the custom WhatsApp parameter:Assuming you added a namedWhatsAppcustom parameter named:

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

3. Obtain general custom content(diytags)

exceptsystemandcontacttags, Anqi CMS also provides a more generaldiyThe label is used to retrieve custom content information that may be defined at other locations 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 there are additional global parameters defined in some content modelsdiyThe label will be your good helper.

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

  • Output general custom parameters:Suppose you have a variable namedAuthorCustom global parameters, you can use:diytags:
    
    {% diy websiteAuthor with name="Author" %}
    <span>网站作者:{{ websiteAuthor }}</span>
    

Practical tips and注意事项

  • Case sensitivity of parameter names:When defining parameter names in the background, although it is recommended to use English, there is no need to worry about case, AnQi CMS will automatically match during template calls.
  • Multi-site support:If you have used the multi-site feature of Anqi CMS and want to call the global parameters of a specific site, you cansystem/contact/diyadd in thesiteIdparameters, for example{% system with name="SiteName" siteId="2" %}of which"2"which is the ID of the target site.
  • HTML content processing:If your custom parameter value contains HTML code (such as copyright information output by a rich text editor), be sure to use it when outputting in the template:|safeA filter to prevent HTML from being escaped and unable to display normally.
    
    {% system siteCopyright with name="SiteCopyright" %}
    <div>{{ siteCopyright|safe }}</div>
    

By using these flexible global parameter calling methods, you can make your Anqi CMS website template more dynamic and easy to manage, thereby more efficiently carrying out content updates and website operations.

Frequently Asked Questions (FAQ)

  1. Ask: How should I properly display if my custom parameters contain HTML code? Answer:When your custom parameter value is in HTML format, it needs to be used when outputting in the template|safeFilter. For example, if you define a "website introduction" parameter that contains HTML in the backgroundSiteIntro, it should be written like this in the template:{% system siteIntroContent with name="SiteIntro" %}{{ siteIntroContent|safe }}. So that the HTML code will be parsed and displayed correctly by the browser.

  2. Question: Why did I set custom parameters in the background, but there is no content displayed when called in the template? Answer:This usually has several reasons. First, please check if thenameThe attribute value matches completely. Next, confirm whether you have added the parameter in the correct background setting area (such as "Global Function Settings" or "Contact Information Settings") and used the corresponding template tag (systemorcontact)。Finally, if it is in a multi-site environment, confirm whether the correctsiteIdSometimes, clearing the system cache (found in the background menu under the 'Update Cache' option) may also resolve display issues.

  3. Ask: How to call global parameters of other sites in a multi-site environment? Answer: ":In the multi-site environment of AnQi CMS, you can call in the following way:system/contactanddiythe tag withsiteIdParameters to specify the global parameters to be called for which site. For example, if you want to get the site with ID2write the site name like this:{% system otherSiteName with name="SiteName" siteId="2" %}This allows cross-site invocation of global parameters.