As an expert in long-term content operation of AnQiCMS, I am well aware of the importance of dynamically obtaining system configuration information in the template.Efficiently display the website name, Logo, and other core elements, which not only ensures the consistency of the brand image but also can flexibly adapt to changes in operation strategy.AnQiCMS's powerful template engine provides intuitive and feature-rich tags, making it easy to obtain these system-level configurations in front-end templates.
This article will delve into how to use the built-insystemtags to obtain the website name, Logo, and other key system configuration information.
Access the core system configuration:systemThe clever use of tags
In AnQiCMS template design,systemThe tag is the key tool to obtain global system configuration information.It allows you to directly extract data from the background configuration, such as the name of the website, Logo image address, filing number, etc.This greatly enhances the flexibility of the template, allowing website information updates without changing the code, just by operating in the background.
systemThe basic syntax of the tag is:{% system 变量名称 with name="字段名称" %}.
Here, 变量名称Is an optional parameter. If you want to store the configuration information obtained in a variable for subsequent use in the template, you can specify a name for it. If omitted变量名称thensystemThe label will directly output the requested field value.
nameThe parameter is indispensable, it specifies the specific configuration item you want to retrieve. Each system configuration has a uniquenameField identifier, through which you can accurately locate the required information.
In a multi-site management environment, if you need to get the configuration information of a specific site rather than the current site,systemLabels also support asiteIdparameter. ThroughsiteIdYou can specify the site ID to be queried to implement cross-site data calls. However, for most single-site application scenarios, this parameter is usually not required.
Practice of obtaining common system configuration information
AnQiCMS backend provides rich system settings options, here are some of the most commonly used and critical configurations, as well as how to obtain them in the template:
Website name (SiteName)The website name is the core of the brand identity, usually displayed in the browser title bar, website header, and other locations. The method to obtain the website name is as follows:
<div>网站名称:{% system with name="SiteName" %}</div>
{# 将网站名称赋值给一个变量以便多次使用 #}
{% system websiteName with name="SiteName" %}
<title>{{ websiteName }} - 我的网站</title>
Website Logo (SiteLogo)Logo is the visual core of the website, dynamically referencing it in the template can conveniently update the brand image.
<img src="{% system with name="SiteLogo" %}" alt="{% system with name="SiteName" %}" />
{# 同样可以赋值给变量 #}
{% system siteLogoPath with name="SiteLogo" %}
<a href="/"><img src="{{ siteLogoPath }}" alt="{% system with name="SiteName" %}" class="header-logo"></a>
Please note,altThe property was used again.SiteNameThis not only helps search engine optimization, but also improves the accessibility of the website.
The home page address (BaseUrl)When building internal links, especially when your website may be deployed on different domain names or subdirectories, dynamically obtainingBaseUrlis very useful.
<a href="{% system with name="BaseUrl" %}">返回首页</a>
Static file address of the template (TemplateUrl)The style sheets, JavaScript files, and image static resources of AnQiCMS templates are usually stored in the template directory./public/static/or a similar structure.TemplateUrlCan help you correctly reference these resources, ensuring that the template can load normally in different environments.
<link href="{% system with name="TemplateUrl" %}/css/style.css" rel="stylesheet">
<script src="{% system with name="TemplateUrl" %}/js/main.js"></script>
Website filing number (SiteIcp) and Copyright Information (SiteCopyright)This information is usually found at the bottom of the website, which is crucial for compliance and copyright statements.
<footer>
<p><a href="https://beian.miit.gov.cn/" rel="nofollow" target="_blank">{% system with name="SiteIcp" %}</a></p>
<div>{% system siteCopyrightContent with name="SiteCopyright" %}{{ siteCopyrightContent|safe }}</div>
</footer>
Please note,SiteCopyrightThe content may contain HTML tags, so it usually needs to be added when used.|safeA filter to prevent HTML from being escaped.
Site language (Language)Used for setting<html>label'slangAn attribute that helps browsers and search engines understand the language used in the page content.
<html lang="{% system with name='Language' %}">
Extended Application: Customizing the acquisition of system parameters.
In the AnQiCMS backend global function settings, in addition to the preset system configuration items, it also allows you to add custom parameters. These custom parameters can also besystemThe tag for obtaining, greatly expands the flexibility of the template. For example, if you add a custom parameter named "ServiceHotline" to store the customer service hotline phone number in the background, you can call it like this in the template:
<div>客服热线:{% system with name="ServiceHotline" %}</div>
HerenameThe value directly corresponds to the custom parameter name you set in the background.
The dynamic year display in the template
Except throughsystemLabel acquisition configuration, when you need to display the current year in the copyright statement or other places,nowThe tag is a convenient auxiliary tool. It can output the current time or year according to the specified format.
<footer>
<p>© {% now "2006" %} {% system with name="SiteName" %}. All Rights Reserved.</p>
</footer>
"2006"Is the Golang format string for representing the year, which outputs a four-digit year.
With these powerful tags, AnQiCMS allows website operators to fully control the display of basic website information, whether it is at the brand level or the technical level, providing great convenience and flexibility.
Frequently Asked Questions (FAQ)
1. Why is the website logo not displaying when I reference it in the template?This usually has several reasons.First, please check if you have uploaded the website Logo image in the AnQiCMS background "Global Function Settings".{% system with name="SiteLogo" %}tags in the template,nameThe parameter spelling is correct, and the image path is valid.Finally, if the image path is correct but it still does not display, it may be due to an issue with the image file itself, or an incorrect configuration of static files on the server side. You can check the network request in the browser developer tools to view the loading status and return code of the Logo image.
2. How do I call a custom parameter that I added in the "Global Feature Settings" in the background?Custom parameters can be used throughsystemtags in conjunction with itsnameCall the parameter. Suppose you have added a custom parameter named "AnalyticsCode" in the background to store the Google Analytics tracking code, then you can use it in the template.{% system with name="AnalyticsCode" %}To get its value. If the value of the custom parameter contains HTML or JavaScript code, it is imperative to use|safefor example:{% system analyticsScript with name="AnalyticsCode" %}{{ analyticsScript|safe }}.
3. Can I access the system configuration of other sites in the current site's template if I enable the multi-site feature in AnQiCMS?Yes, AnQiCMS'systemTags support throughsiteIdParameters to specify which site's configuration information to retrieve. For example, if you want to get the configuration information for a site with ID2, you can use the site's name,{% system with name="SiteName" siteId="2" %}This is very useful in the scenario of building aggregation information pages or sharing certain configurations across multiple sites.