How to get and display the system parameters configured in the global settings of the AnQiCMS template?

In the AnQiCMS template, efficiently obtaining and displaying the system parameters configured in the background "Global Settings" is the key to ensuring the uniformity of website information and convenient management.AnQiCMS provides a set of intuitive and powerful template tags, allowing developers and operators to easily achieve this goal without delving into complex programming code.

The global settings are a core component of the AnQiCMS backend, which centrally manages the basic information of the website, such as the website name, Logo, record number, copyright information, basic URL, mobile end URL, language settings, and even custom extended parameters.Centralize this information and dynamically call it in the template, which can greatly improve the maintainability and content update efficiency of the website.When the website information needs to be adjusted, it only needs to be modified once in the background, and all the places that call this parameter will be automatically updated, avoiding omissions or errors that may be caused by manual modification of template files.

Core function:{% system %}The use of tags

In AnQiCMS templates, the retrieval and display of global settings parameters mainly rely on a named{% system %}The label. This label is specifically designed for system-level parameter calls and is very flexible to use.

Its basic syntax is{% system 变量名称 with name="字段名称" %}where the field name needs to correspond to the English name of the parameter in the background global settings. If you just want to output the value of the parameter, you can omit the 'variable name' part.

Let's take a look at how to obtain and display some commonly used built-in system parameters:

  • Website name (SiteName)The website name is usually displayed in the website's title bar, header, or footer, representing the brand of the website.

    <title>{{ tdk with name="Title" siteName=true }}</title> {# 结合TDK标签自动添加网站名称 #}
    <h1>{% system with name="SiteName" %}</h1>
    

    Here we demonstrate two common usages: one is to combinetdkThe tag automatically adds the website name to the page title, and the other is to directly retrieve and display the website name.

  • Website Logo (SiteLogo)The website logo is the visual identity of the website, usually a picture link.

    <img src="{% system with name="SiteLogo" %}" alt="{% system with name="SiteName" %}" />
    

    BysrcReference the logo image while using the attributeSiteNameasaltThe attribute value, helpful for SEO and accessibility.

  • Website filing number (SiteIcp)If your website has a record information, it can be displayed in the footer.

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

    Not only is the record number displayed here, but a link to the Ministry of Industry and Information Technology record query website is also added, and it is set.nofollowProperty.

  • Copyright content (SiteCopyright)The website copyright information is usually included in the footer, may contain HTML tags, such as year, company name, etc.

    <div>{% system siteCopyright with name="SiteCopyright" %}{{siteCopyright|safe}}</div>
    

    It is noteworthy that copyright content may include HTML tags (such as © symbols, links, etc.), in order for these tags to be correctly parsed and rendered by the browser, we need to use|safefilter.

  • The home page address (BaseUrl) BaseUrlIt is the root address of the website, which is very useful when constructing absolute paths or linking to the homepage.

    <a href="{% system with name="BaseUrl" %}">返回首页</a>
    
  • Static file address of the template (TemplateUrl)This parameter helps you correctly refer to CSS, JavaScript, images, and other static resources within the template.

    <link href="{% system with name="TemplateUrl" %}/css/style.css" rel="stylesheet">
    
  • Site language (Language)This parameter is very useful for multilingual websites or when you need to declare the current page language in HTML tags.

    <html lang="{% system with name='Language' %}">
    

Advanced Application: Customizing system parameter retrieval

AnQiCMS's global settings are not limited to built-in parameters, but also allow you to add custom parameters according to your actual needs.This means you can create any key-value pair you need, such as customer service hotline, company mission, catchy slogan, and so on, and call it in the template.

In the "Global Settings" on the backend, find the "Custom Settings Parameters" section, where you can add new parameter names, parameter values, and notes. For example, if you add a parameter namedWeChatOfficialAccountThe parameter of (WeChat Official Account) is filled with the specific name of the official account.

The way to get this custom parameter in the template is the same as getting built-in parameters, justnameset the property to your custom "parameter name".

<div>关注我们的微信公众号:{% system with name="WeChatOfficialAccount" %}</div>

In this way, a close connection is established between the website template and the backend configuration, greatly enhancing the flexibility of content operation.

Parameter acquisition under a multi-site environment

AnQiCMS supports multi-site management, if you run multiple sites and need to access global parameters of other sites in a template of a certain site,{% system %}The tag also provides a solution. You can addsiteIdparameters to specify which site's parameters to retrieve.

{# 获取 ID 为 2 的站点的网站名称 #}
<div>兄弟网站名称:{% system with name="SiteName" siteId="2" %}</div>

Please note,siteIdIt is usually not necessary to fill in, as the parameters of the current site are automatically obtained. It is only used when cross-site references are needed.

Points to note in practice

  1. Cache refresh:After modifying the global settings in the background, the front-end page may not be updated immediately, because AnQiCMS usually enables caching to improve access speed.At this time, you need to manually click the "Update Cache" feature in the background, or wait for the cache to automatically expire.
  2. Case sensitivity of parameter names:AnQiCMS template tags are case-sensitive. Please ensurenameThe field name filled in the attribute must be exactly the same as the parameter name set in the background (or the built-in parameter name).
  3. Security and|safeFilter:When the value of the custom parameter may contain HTML content (such as a script, a complex HTML structure), be sure to use it in the output.|safeFilter. This is to inform the template engine that this content is safe and does not require HTML escaping.But you also need to ensure that the users entering these custom parameters are trustworthy to avoid potential XSS attacks.
  4. Test verification:After modifying the template or backend parameters, it should be carefully tested on the front-end page to ensure that the information is displayed correctly and the functions run normally.

By mastering the use of{% system %}Tags and their related attributes, you can make AnQiCMS templates more dynamic and maintainable, thereby more efficiently managing your website content.


Frequently Asked Questions (FAQ)

Q1: I modified the website name in the background "Global Settings", but why didn't the front-end page update immediately?A1: AnQiCMS usually enables caching to improve website performance.After you modify the background settings, the old data on the front-end page may still be in the cache.You need to log in to the backend, find and click the "Update Cache" button, clear the website cache, so that the front-end page will display the latest settings.

Q2: Besides built-in parameters, what types of parameters can I obtain? How to configure?A2: AnQiCMS supports custom system parameters.You can find the "Custom Settings Parameters" area at the bottom of the "Global Settings" page in the background.In here, you can add a new "parameter name" (as a template innameThe value of the attribute), "parameter value" (the actual displayed content), and "remark". For example, you can add a parameter namedSupportEmailto store your customer service email.

Q3: Can I retrieve system parameters for the current site and other sites in the same template?A3: Yes.{% system %}The tag supports onesiteIdParameters. By default, it will retrieve the parameters of the current site. If you want to get the website name of the site with ID 2, you can use it like this:{% system with name="SiteName" siteId="2" %}But make suresiteIdThe site exists and you have permission to access its information.