In AnQiCMS templates, efficiently obtaining and displaying system parameters configured in the "Global Settings" of the backend is the key to ensuring unified 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.
Global settings are the core components of AnQiCMS backend, which centrally manage the basic information of the website, such as website name, Logo, filing number, copyright information, basic URL, mobile end URL, language settings, and even customized extended parameters.Manage this information uniformly 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 the template files.
Core Function:{% system %}The Use of Tags
In AnQiCMS templates, obtaining and displaying global settings parameters mainly relies 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="字段名称" %}. The field name should correspond to the English name of the parameter in the background global settings. If you just want to output the parameter value directly, you can omit the 'variable name' part.
Let's take a look at how to get and display some commonly used built-in system parameters:
Website name (
SiteName)The website name is usually displayed in the title bar, header, or footer of the website, representing the brand of the website.<title>{{ tdk with name="Title" siteName=true }}</title> {# 结合TDK标签自动添加网站名称 #} <h1>{% system with name="SiteName" %}</h1>Here we show two common uses: one is to combine
tdkThe tag automatically adds the site name to the page title, and the other is to directly obtain and display the site name.Website Logo (
SiteLogo)The website logo is the visual identification of the website, usually a link to an image.<img src="{% system with name="SiteLogo" %}" alt="{% system with name="SiteName" %}" />Pass
srcReference the Logo image while using properties.SiteNameasaltAttribute value, helpful for SEO and accessibility.Website filing number (
SiteIcp)If your website has filing 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>It not only shows the filing number but also adds a link to jump to the Ministry of Industry and Information Technology filing query website and sets
nofollowproperties.Copyright content (
SiteCopyright)The copyright information of the website is usually included in the footer, and may contain HTML tags, such as the year, company name, etc.<div>{% system siteCopyright with name="SiteCopyright" %}{{siteCopyright|safe}}</div>It is worth noting that as the copyright content may contain 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.Website Home Address (
BaseUrl)BaseUrlIt is the root address of the site, which is very useful when building absolute paths or linking to the homepage.<a href="{% system with name="BaseUrl" %}">返回首页</a>Template Static File Address (
TemplateUrl)This parameter helps you correctly reference CSS, JavaScript, or images, etc., within the template.<link href="{% system with name="TemplateUrl" %}/css/style.css" rel="stylesheet">Site language (
Language)For a multilingual website, or when you need to declare the current page language in HTML tags, this parameter is very useful.<html lang="{% system with name='Language' %}">
Advanced Application: Customizing the retrieval of system parameters
AnQiCMS's global settings are not limited to built-in parameters, it also allows you to add custom parameters according to your actual needs.This means you can create any key-value pairs you need, such as customer service hotline, company mission, and special slogans, and call them in the template.
In the background “Global Settings”, find the “Custom Setting Parameters” section, where you can add new parameter names, parameter values, and notes. For example, if you add a parameter named “WeChatOfficialAccountThe parameter of the (WeChat Official Account) and filled in the specific public account name in its parameter value.
The way to get this custom parameter in the template is exactly the same as getting built-in parameters, justnameset the property to your custom "parameter name".
<div>关注我们的微信公众号:{% system with name="WeChatOfficialAccount" %}</div>
This way, a tight connection is established between the website template and the background configuration, greatly enhancing the flexibility of content operation.
Parameter acquisition in a multi-site environment
AnQiCMS supports multi-site management, if you have multiple sites running and need to access global parameters of other sites in a template of a certain site,{% system %}Tags also provide solutions. 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
- Cache refresh:After modifying the global settings in the background, the front-end page may not be updated immediately. This is 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 expire automatically.
- Parameter name case sensitivity:AnQiCMS's template tags are case-sensitive. Please make sure
nameThe field name filled in the attribute must be exactly consistent with the parameter name set in the background (or the built-in parameter name) in terms of case. - Security and
|safeFilter:When the value of a 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 who input these custom parameters are trustworthy to avoid potential XSS attacks. - Test verification:Each time the template or background parameters are modified, the front-end page should be tested carefully to ensure that the information is displayed correctly and the functions run normally.
By skillfully applying{% system %}Tags and their related properties, you can make AnQiCMS templates more dynamic and maintainable, thereby more efficiently managing your website content.
Common Questions (FAQ)
Q1: Why didn't the front-end page update immediately after I modified the website name in the "Global Settings" on the backend?A1: AnQiCMS to improve website performance, cache is usually enabled.When 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 back end, find and click the 'Update Cache' button, clear the website cache, and 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.nameProperties value), 'Parameter value' (actual displayed content) and 'Notes'. For example, you can add a parameter namedSupportEmailto store your customer service email.
Q3: Can I get the system parameters of the current site and other sites at the same time in the same template?A3: Yes, you can.{% system %}The tag supports asiteIdParameters. By default, it retrieves 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 sure thatsiteIdThe corresponding site exists, and you have permission to access its information.