When building a website, some core information such as the website name, website logo, record 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 an intuitive and flexible way to manage and present these system-level information in templates.
Where can I set these global information?
Firstly, all these important website information need to be unifiedly configured in the AnQiCMS backend.Generally, you can find the 'Global Function Settings' under 'Background Settings' in the background navigation menu.
In this interface, you can easily input and adjust the following information:
- Website NameThe name of your website or brand, 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 identity.
- Filing 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 owner of the website content.
- In addition, there are other important global settings such as website address, mobile end address, default language package, as well as 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 special template tag for retrieving the global system configurationsystemThis 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 "Global Function Settings" on the backend. You can choose to directly output the value of this field, or assign it to a变量名称Then, use this variable in other parts of the template.
Next, let's take a look at several commonly used global information as examples, and see how they are retrieved and displayed in the template.
1. Display the website name
The website name is usually in<title>tags, headers, footers, and other key positions on the page.
{# 直接输出网站名称 #}
<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 example, we demonstrated two ways to obtain the website name.<title>In the tag, we used a more professional approach.tdkTags automatically combine the title and website name, it can also append the website name configured in the background to the page title while fetching the page title.siteName=trueParameters automatically append the website name configured in the background to the end of the page title.<h1>and<p>In tags, we use directlysystemTags or through variablessiteNameVarTo display the website name.
2. Display website Logo
The website logo is an important part of brand recognition, usually displayed in the header in the form of 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>
When displaying the logo, in addition tosrcThe attribute points to the Logo image address (provided{% system with name="SiteLogo" %}), we strongly recommend that you also define the<img>Label addaltattribute.altThe value of the attribute 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 record number
If your website has a record number, it is usually 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"properties.nofollowThe attribute tells the search engine not to follow this link, as it is an external, possibly unrelated government website link;target="_blank"Then open the link in a new window or a new tab to avoid visitors leaving your website.
4. Display copyright information
Copyright information is typically located at the bottom of a website page, declaring the ownership of the website content. Since copyright information may contain HTML tags (such as©Symbols, links, etc., should be paid special attention to when used.
{# 将版权信息赋值给变量并使用 |safe 过滤器输出 #}
{% system copyrightInfo with name="SiteCopyright" %}
<p>
{{ copyrightInfo|safe }}
</p>
{# 结合当前年份显示 #}
<footer>
<p>
© {% now "2006" %} {{ copyrightInfo|safe }}
</p>
</footer>
This needs to be emphasized specially.|safeFilter. If the copyright information in the background contains HTML tags, and you want these tags to be correctly parsed by the browser instead of being displayed as plain text, you must use|safeFilter. Otherwise, like©such HTML entities will be displayed as is, not as copyright symbols©. At the same time, you can also combine{% now "2006" %}Label dynamically displays the current year, keeping the copyright information up to date.
5. Other common global information.
In addition to the above several items,systemThe label can also obtain other useful global information:
- Website Home Address (
BaseUrl) Useful when constructing absolute links in templates.{{ "%s/some-page"|format(system.BaseUrl) }} - Template Static File Address (
TemplateUrl): Points to the directory of static resources (CSS, JS, images) for the current template.<link href="{% system with name="TemplateUrl" %}/css/style.css" rel="stylesheet"> - Site language (
Language): Available for<html>Tagslangattributes, which help with internationalization and SEO.<html lang="{% system with name='Language' %}">
6. Getting Custom Parameters
If you have added custom parameters in the "Global Feature Settings" backend (for example, a parameter namedSupportEmailthe customer service email), you can also retrieve them in the template in the same way:
{% system supportEmail with name="SupportEmail" %}
<p>客服邮箱:<a href="mailto:{{ supportEmail }}">{{ supportEmail }}</a></p>
Summary
PasssystemTags, 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 the creation and operation of website content.Effectively using these tags can greatly enhance the maintenance efficiency of templates and the overall user experience of the website.
Common Questions (FAQ)
Why does the HTML link I included in the copyright information set in the background display directly as HTML code in the foreground instead of a clickable link?
A1:This is because AnQiCMS template engine defaults to performing security escaping on the output content to prevent XSS attacks. If you want the HTML code to be normally parsed, you need to use|safeFilter. For example, if your copyright information is© 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 if my website has the multi-site feature enabled, rather than the current site's settings? A2:`