How to get and display the global settings information of a website in a template, such as the website name, Logo, and filing number?

When building website templates in AnQiCMS, we often need to display some common information at the website level, such as the website name, Logo image, and legal record number required by the law.This information is usually managed in the global settings on the backend to ensure consistency across the entire site and for ease of maintenance.systemTags make it very intuitive and efficient to access and display these global settings in the template.

Understanding global settings withsystemtags

AnQiCMS classifies some core configurations of the website as 'Global Settings', and these settings will immediately affect all pages of the website once modified. To flexibly call this information in the template, the system provides a specialsystemLabel.

systemThe basic usage of the label is:{% system 变量名称 with name="字段名称" %}.

Here are the变量名称is an optional parameter, you can use it to temporarily store the retrieved settings value, so that it can be reused in the template or processed more complexly.nameThe parameter specifies the field name of the specific global setting item you want to retrieve, for example,SiteNameUsed for the website name,SiteLogoUsed for the website logo, etc.

Retrieve and display the website name (SiteName)

The website name is the facade of the website, which is usually displayed on the page<title>Tags, headers, footers, and other key positions. After configuring the "Website Name" in the "Global Settings" of AnQiCMS backend, you can use the following method to get it in the template:

<title>{% tdk with name="Title" siteName=true %}</title>
{# 或者,如果你只想获取网站名称本身,不带页面标题和分隔符 #}
<h1>{% system with name="SiteName" %}</h1>

In the above example,{% tdk with name="Title" siteName=true %}It is a better practice to get the page title, which will automatically concatenate the current page's title with the website name and provide options for separators. If your website name is included in the HTML content (e.g., with emphasis tags), you may also need to consider using|safeFilter to avoid HTML entity escaping.

Get and display the website logo (SiteLogo)

The website logo is the visual identifier of the brand, and almost every website will display it in the header section. Assuming you have uploaded the website logo image in the "Global Settings" backend, displaying it in the template will be very simple:

<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 image path of the Logo,SiteLogo), but also wrapped it in a link pointing to the homepage of the website.BaseUrl)。SiteNameasaltthe value of the attribute.

Get and display the record number (SiteIcp)

For websites operating in mainland China, the filing number is a legally required piece of information that must be displayed, usually placed at the footer of the website. After filling in the "Filing Number" in the "Global Settings

<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 also added withrel="nofollow"andtarget="_blank"attributes, all of which are common web development practices.

Retrieve and display copyright information (SiteCopyright)

Copyright information is also a common element in website footers, which protects the legal rights of the content. After filling in 'Copyright Content' in the 'Global Settings' backend, it can be displayed in the template like this:

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

It is noteworthy that if the copyright information you fill in the background may contain HTML tags (for example&copy;symbols, links, etc.), then when using{% system siteCopyright ... %}{{ siteCopyright }}, you need to add an extra|safeFilter. This is because AnQiCMS's template engine defaults to escaping output variables as 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 several core settings,systemtags can also obtain more preset global information, such as:

  • Home page address (BaseUrl): {% system with name="BaseUrl" %}[en] Used to construct absolute path links.
  • [en] Template static file address (TemplateUrl): {% system with name="TemplateUrl" %}[en] Convenient for referencing CSS, JS, and other static resources under the template directory.
  • Site Language (Language): {% system with name="Language" %}which can be used to set HTML'slangattributes, for example<html lang="{% system with name='Language' %}">.

The strength of AnQiCMS also lies in the fact that it allows you to add in the "global settings" on the backendCustom ParametersIf your website needs to display some global information without preset fields (such as "customer service phone numberCustomerPhoneThen in the template, you can retrieve its value using{% system with name="CustomerPhone" %}This provides great convenience for the flexibility and scalability of the template.

Summary

By using flexibilitysystemTags, AnQiCMS makes the global settings call 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, thereby building a more robust and maintainable website.


Common Questions (FAQ)

  1. Why is my website logo or filing number not displayed, or displayed incorrectly?Answer: First, please make sure you have correctly filled in the "Website Logo" and "Record Number" information in the "Global Settings" of the AnQiCMS backend.For the Logo, you need to check if the path of the uploaded image is valid.If the image path is correct but the image still does not display, it may be a browser cache issue. Try clearing the browser cache and refreshing the page.siteIdParameters specify the settings for a specific site.

  2. Question: 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.CustomerServicePhoneIn the template, you can use{% system with name="CustomerServicePhone" %}Get and display this custom information. This greatly enhances the flexibility of the template.

  3. Q: If I manage multiple sites, how can I get the global settings of different sites in the template?Answer: AnQiCMS'ssystemtag supportsiteIdParameters. If you want to get the global settings of a specific site (not the current site), you cansystemspecify in the tag.siteIdFor 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.