When building website templates in AnQiCMS, we often need to display some general information at the website level, such as the website name, Logo image, and legal filing number required by law.This information is usually managed in the background global settings to ensure consistency across the entire site and facilitate maintenance.AnQiCMS's powerful template tag system, especiallysystemLabels make it very intuitive and efficient to retrieve and display these global settings in the template.
Understanding global settings andsystemTag
AnQiCMS categorizes some of the core configurations of the website as "Global Settings", which, once modified, will immediately affect all pages of the website. To flexibly call this information in the template, the system provides a specialsystem.
systemThe basic usage of tags is:{% system 变量名称 with name="字段名称" %}.
Here变量名称is an optional parameter, you can use it to temporarily store the obtained setting values, so that they can be reused in templates or undergo more complex processing.nameThe parameter specifies the field name of the specific global setting item you want to retrieve, for exampleSiteNameUsed for website name,SiteLogoUsed for website logo, etc.
Get and display the website name (SiteName)
The website name is the facade of the website and usually appears on the page<title>Labels, headers, footers, and other key positions. After configuring the "Website Name" in the "Global Settings" of AnQiCMS backend, you can obtain it in the template using the following method:
<title>{% tdk with name="Title" siteName=true %}</title>
{# 或者,如果你只想获取网站名称本身,不带页面标题和分隔符 #}
<h1>{% system with name="SiteName" %}</h1>
In the above example,{% tdk with name="Title" siteName=true %}Is a better practice to get the page title, it will automatically concatenate the current page title and website name, and provide options for separators. If your website name is included in the HTML content (for example, with emphasis tags), you may also consider using|safeA filter to avoid HTML entity escaping.
Get and display the website logo (SiteLogo)
The website logo is the visual symbol of the brand, almost every website will display it in the header section. Assuming you have uploaded the website logo image in the "Global Settings" backend, it will be very simple to display it in the template:
<div class="header-logo">
<a href="{% system with name="BaseUrl" %}">
<img src="{% system with name="SiteLogo" %}" alt="{% system with name="SiteName" %}" />
</a>
</div>
In this example, we not only obtained the path of the Logo image (SiteLogo), but also wrapped it in a link pointing to the homepage of the website (BaseUrl)。For SEO friendliness and accessibility, we useSiteNameasaltthe value of the attribute.
Get and display the filing number (SiteIcp)
For websites operating in mainland China, the filing number is a legal requirement that must be displayed as information, usually placed at the footer of the website. After filling in the 'Filing Number' in the 'Global Settings' of AnQiCMS backend, you can display it in the template like this:
<p class="footer-icp">
<a href="https://beian.miit.gov.cn/" rel="nofollow" target="_blank">
{% system with name="SiteIcp" %}
</a>
</p>
Here, the record number is placed in a link that points to the Ministry of Industry and Information Technology record query website and is added withrel="nofollow"andtarget="_blank"properties, all of which are common web development practices.
Get and display the copyright information (SiteCopyright)
Copyright information is also a common element in the website footer, which protects the legal rights of the content. After filling in "Copyright Content" in the background "Global Settings", it can be displayed like this in the template:
<div class="footer-copyright">
{% system siteCopyright with name="SiteCopyright" %}
{{ siteCopyright|safe }}
</div>
It is noteworthy that the copyright information you enter in the background may contain HTML tags (such as©symbols, links, etc.), then when using{% system siteCopyright ... %}{{ siteCopyright }}you need to add extra|safeFilter. This is because the AnQiCMS template engine defaults to escaping output variables with HTML entities to prevent XSS attacks.|safeThe filter tells the template engine that this content is safe and does not need to be escaped, ensuring that the HTML content is rendered correctly.
Get other commonly used global settings and custom parameters
In addition to the above core settings,systemtags can also obtain more preset global information, such as:
- Website home page address (BaseUrl):
{% system with name="BaseUrl" %}It is usually used to construct absolute path links. - Template static file address (TemplateUrl):
{% system with name="TemplateUrl" %}Convenient for referencing CSS, JS, and other static resources under the template directory. - Site Language (Language):
{% system with name="Language" %}Can be used to set the HTML'slangproperties, such as<html lang="{% system with name='Language' %}">.
The strength of AnQiCMS lies in its ability to add in the background "Global Settings"Custom parameter. If your website needs to display some global information without predefined fields (such as 'customer service phone number', 'company email' etc.), you can add a custom parameter in the background, for example, with the parameter nameCustomerPhone. Then you can access it in the template{% system with name="CustomerPhone" %}This provides great convenience for the flexibility and scalability of the template.
Summary
By flexible applicationsystemTags, AnQiCMS makes the call to the global settings of the website extremely simple and efficient.It not only simplifies the template development process, but more importantly, ensures the consistency of website information, facilitates future content updates and multi-site management, and thus builds a stronger and easier to maintain website.
Frequently Asked Questions (FAQ)
Ask: Why isn't my website logo or filing number displayed, or is displayed incorrectly?Answer: Firstly, make sure you have correctly filled in the 'Website Logo' and 'Record Number' information in the 'Global Settings' of the AnQiCMS background.For the logo, you also need to check if the path of the image you uploaded is valid.If the image path is correct but it still does not display, it may be a browser cache issue. Try clearing the browser cache and refreshing the page.Moreover, if you are a multi-site user, please confirm whether the template needs to be approved through
siteIdThe parameter specifies the settings for a specific site.Ask: Can I get other custom global information besides the preset website name, Logo, etc.?Of course you can. AnQiCMS allows you to add custom parameters on the "Global Settings" page in the backend.For example, you can add a parameter named 'Customer Service Phone Number' with the field name (for template calls) of
CustomerServicePhoneIn the template, you can use{% system with name="CustomerServicePhone" %}Get and display this custom information. This greatly increases the flexibility of the template.Question: If I manage multiple sites, how can I get the global settings of different sites in the template?Answer: AnQiCMS'
systemTag supportsiteIdParameter. If you want to get the global settings of a specific site (not the current site), you cansystemExplicitly specify in the tagsiteIdFor example,{% system with name="SiteName" siteId="2" %}It will retrieve the website name of the site with ID 2. This is very useful for building shared modules or cross-referencing information under multi-site management.