How to retrieve and display the system global settings of AnQiCMS template, such as website name, Logo, filing number, and copyright information?

When building a website, some core information such as the website name, website logo, filing number, and copyright information are indispensable elements.These global settings not only help visitors quickly identify your brand, but also reflect the professionalism and compliance of the website.AnQiCMS provides a直观而灵活的方式来管理和在模板中呈现这些系统级的信息方式。

Where can I set these global information?

First, all this important website information needs to be unifiedly configured in the AnQiCMS backend.usually, you can find the 'background settings' under the background navigation menu, which includes 'global feature settings'.

In this interface, you can easily enter and adjust the following information:

  • Website NameYour website or brand name, which is usually displayed in the browser tab or at the top of the website page.
  • Website LogoUpload your brand logo image, which will be the core of the website's visual recognition.
  • Record numberIf your website operates in mainland China and has been registered, you can fill in the registration number here.
  • Copyright informationIt is usually displayed in the footer of the website, used to declare the copyright of the website content.
  • In addition, there are other important global settings such as website address, mobile end address, default language package, and the ability to add custom parameters to meet more personalized needs.

After completing these settings, this information will be stored in the system, waiting for your template to call it.

How can you retrieve and display this information in the template?

AnQiCMS provides a template tag specifically used to obtain the global system configuration—system. This tag is very flexible and can help us retrieve the required global settings in any template file of the website.

UsesystemThe basic syntax of the tag is like this:{% system 变量名称 with name="字段名称" %}

here,字段名称Corresponding to the internal identifiers of each configuration item in the background "Global Function Settings". You can choose to output the value of this field directly, or assign it to a变量名称Then use this variable in other places of the template.

Next, let's take a look at several commonly used global information examples to see how they are obtained and displayed in the template.

1. Display the website name

The website name usually appears on the<title>tags, headers, or footers and other key positions.

{# 直接输出网站名称 #}
<title>{% tdk with name="Title" siteName=true %}</title> {# 使用tdk标签自动组合标题和网站名 #}
<h1>欢迎访问 {% system with name="SiteName" %}</h1>

{# 也可以将网站名称赋值给一个变量再使用 #}
{% system siteNameVar with name="SiteName" %}
<p>当前网站的名称是:{{ siteNameVar }}</p>

In the above examples, we have shown two ways to obtain the website name. In<title>Labels, we used a more professionaltdkLabels automatically handle the combination of page titles and website names, while obtaining the page title, it can also pass throughsiteName=trueThe parameter automatically appends the website name configured in the background to the page title. And in<h1>and<p>tags, we use them directlysystemtags or through variablessiteNameVarTo display the website name.

2. Display website Logo

The website logo is an important part of brand identification, usually displayed in the header as an image.

{# 直接输出网站Logo图片 #}
<img src="{% system with name="SiteLogo" %}" alt="{% system with name="SiteName" %} Logo" />

{# 也可以将Logo地址赋值给一个变量再使用 #}
{% system siteLogoUrl with name="SiteLogo" %}
{% system siteNameForLogo with name="SiteName" %}
<a href="/">
    <img src="{{ siteLogoUrl }}" alt="{{ siteNameForLogo }} 的Logo" />
</a>

In displaying the logo, in addition tosrcThe attribute points to the address of the Logo image (provided{% system with name="SiteLogo" %}by us, we strongly recommend that you set<img>tagsaltthis attribute.altThe value is usually the website name, which not only helps search engines understand the content of the image, but also provides meaningful text alternatives when the image cannot be loaded.

3. Display the filing number

If your website has a record number, it will usually be displayed in the footer of the website and linked to the Ministry of Industry and Information Technology record query website.

{# 直接输出备案号并添加链接 #}
<p>
    <a href="https://beian.miit.gov.cn/" rel="nofollow" target="_blank">
        {% system with name="SiteIcp" %}
    </a>
</p>

{# 也可以通过变量来组织显示 #}
{% system icpNumber with name="SiteIcp" %}
{% if icpNumber %} {# 判断备案号是否存在,再进行显示 #}
<p>
    本网站由 <a href="https://beian.miit.gov.cn/" rel="nofollow" target="_blank">{{ icpNumber }}</a> 提供备案支持。
</p>
{% endif %}

In the above code, we usedrel="nofollow"andtarget="_blank"Property.nofollowThe attribute tells the search engine not to track this link because it is an external, possibly unrelated government website link;target="_blank"Open the link in a new window or tab to avoid visitors leaving your website.

4. Display copyright information

Copyright information is usually located at the footer of the website, declaring the ownership of the website content. Since copyright information may contain HTML tags such as&copy;Symbols, links, etc., should be paid special attention to when used.

{# 将版权信息赋值给变量并使用 |safe 过滤器输出 #}
{% system copyrightInfo with name="SiteCopyright" %}
<p>
    {{ copyrightInfo|safe }}
</p>

{# 结合当前年份显示 #}
<footer>
    <p>
        &copy; {% now "2006" %} {{ copyrightInfo|safe }}
    </p>
</footer>

It needs to be emphasized here|safeA filter. If the background copyright information contains HTML tags and you want these tags to be parsed correctly by the browser rather than displayed as plain text, you must use|safeFilter. Otherwise, like&copy;The HTML entity will be displayed as is, not a copyright symbol©. You can also combine with{% now "2006" %}Tag dynamically displays the current year, keeping the copyright information up to date.

5. Other common global information

In addition to the above items,systemthe tag can also obtain other useful global information:

  • The home page address (BaseUrl): Very useful when building absolute links in templates.{{ "%s/some-page"|format(system.BaseUrl) }}
  • Static file address of the template (TemplateUrl)Points to the directory of static resources (CSS, JS, images) of the current template.<link href="{% system with name="TemplateUrl" %}/css/style.css" rel="stylesheet">
  • Site language (Language)Can be used for<html>label'slangproperties, which help with internationalization and SEO.<html lang="{% system with name='Language' %}">

6. Retrieving custom parameters

If you add custom parameters (such as, one namedSupportEmailcustomer service email), you can also access them in the template in the same way:

{% system supportEmail with name="SupportEmail" %}
<p>客服邮箱:<a href="mailto:{{ supportEmail }}">{{ supportEmail }}</a></p>

Summary

BysystemLabel, AnQiCMS provides an extremely convenient way to manage and present the global configuration information of the website. Whether you are displaying basic website information, referencing static resource paths, or calling custom configuration items,systemTags can help you complete tasks in a concise and efficient manner, allowing you to focus more on creating and operating website content.Correctly using these tags can greatly enhance the maintenance efficiency of the template and the overall user experience of the website.


Frequently Asked Questions (FAQ)

Q1: Why does the HTML link I set in the background display the HTML code directly instead of a clickable link when displayed on the front end? A1:This is because the AnQiCMS template engine defaults to escaping output content to prevent XSS attacks. If you want HTML code to be parsed normally, you need to use|safeFilter. For example, if your copyright information is&copy; 2023 <a href="/">我的网站</a>, it should be written as in the template{{ copyrightInfo|safe }}.

Q2: How do I retrieve the global settings for a specific site when my website has the multi-site feature enabled, rather than the current site? A2:`