As an experienced website operation expert, I am happy to discuss with you how to efficiently and flexibly obtain the current system configuration information of AnQiCMS templates.This is not only the foundation of template development, but also the key to ensuring the uniformity and maintainability of website information.AnQiCMS is an enterprise-level content management system developed based on the Go language, its concise and efficient design philosophy is also reflected in the use of template tags, making the technical information in the template level call very intuitive.
Smart usesystemLabel: The all-purpose key for website information
In the AnQiCMS template system, you will find an extremely core and powerful tool - that issystemLabel. It is like a '万能钥匙' that can help you easily unlock and display the core configurations of the website, whether it is the website name, Logo image, or filing information, copyright statement, or even the global parameters you customize, all of which can be called through it in the template.
ThissystemThe basic usage of tags is very intuitive, its structure is usually like this:{% system 变量名称 with name="字段名称" %}Of course, if you just want to output the value of a field directly, you can omit变量名称part, just write it directly{% system with name="字段名称" %}. Here,nameThe attribute is the key information you tell the system which configuration information you want to obtain.
Next, let's take a look at some of the most commonly used and most representative ones.systemLabel practical value configuration information and its calling method.
Website name (SiteName): Your brand identification
The website name is the basic identity of each website. In the AnQiCMS background "Global Settings", you will set a name for your website, such as "AnQiCMS Official Website".When you need to display this name at the title, navigation bar, or footer of a website, you can use it.name="SiteName"to get:
{# 直接输出网站名称 #}
<h1>{% system with name="SiteName" %}</h1>
{# 将网站名称赋值给一个变量再使用,方便复杂场景 #}
{% system websiteName with name="SiteName" %}
<title>{{ websiteName }} - **内容管理系统</title>
This method avoids repeating the hard-coded website name in multiple template files, and once the backend is modified, the front-end will also automatically update, greatly improving maintenance efficiency.
Website Logo (SiteLogo): carrier of visual images
The logo is the visual soul of the website. In the AnQiCMS backend, you can upload the website's logo image.In the template, it is equally simple to retrieve and display this logo image:
{# 获取网站Logo的URL并显示,同时使用网站名称作为图片的alt属性 #}
<a href="{% system with name="BaseUrl" %}">
<img src="{% system with name="SiteLogo" %}" alt="{% system with name="SiteName" %} Logo">
</a>
Here we not only obtain the URL of the Logo image, but also combine the website name as the image'saltattribute, which is a very good practice for SEO and accessibility. At the same time,BaseUrlThe use of tags ensures that the Logo link always points to the homepage, even if the domain changes, no template modification is required.
Other important global configuration information
In addition to the website name and Logo,systemThe label can help you obtain many other important global configurations, which are indispensable when building a website:
- Record number (
SiteIcp)If your website has filing information, it is usually required to be displayed in the footer. You can call it like this:<p> <a href="https://beian.miit.gov.cn/" target="_blank" rel="nofollow"> {% system with name="SiteIcp" %} </a> </p> - Copyright content (
SiteCopyright): The website footer usually contains copyright information. Considering that the copyright information may contain HTML tags (such as links), you may need to cooperate with|safeFilter to ensure the correct parsing of HTML content:{% system copyrightInfo with name="SiteCopyright" %} <p>{{ copyrightInfo|safe }}</p> - The home page address (
BaseUrl)This configuration is very practical, especially when building navigation, breadcrumbs, or any links that need to point to the root directory of the website.It ensures that your link is always the correct absolute path in any environment.<a href="{% system with name="BaseUrl" %}">返回首页</a> - Static file address of the template (
TemplateUrl): When developing templates, your CSS, JavaScript, and image static resources are usually stored in/public/static/In the directory and through/templateTemplates in the template folder.TemplateUrlThis will help you build the correct static resource path, ensuring that styles and scripts load correctly:<link rel="stylesheet" href="{% system with name="TemplateUrl" %}/css/style.css"> <script src="{% system with name="TemplateUrl" %}/js/main.js"></script> - Site language (
Language)This is for multilingual websites:<html>TaglangThe property setting is very useful, helping browsers and search engines to better understand the language used in the website content:<html lang="{% system with name="Language" %}">
Custom parameters: meet personalized needs
AnQiCMS's flexibility is also reflected in its ability to add custom parameters in the background "Global Settings". For example, you may have added a parameter named "Customer Service Phone" whose参数名is set toCustomerPhoneSo in the template, you can access it like built-in fields:
<p>客服热线:{% system with name="CustomerPhone" %}</p>
This allows AnQiCMS to easily adapt to various complex website operation requirements without modifying the core code.
Tips in practice
- Calling in a multi-site environmentIf you manage multiple sites in AnQiCMS and want to call the configuration information in the template of the current site,other sitesparameter.
systemLabels also support asiteIdFor example, to get the ID of2write the site name like this:{% system with name="SiteName" siteId="2" %}This is very useful when building cross-site content or integrating services. - Variable assignment and direct outputWhen you need to further process the configuration information you have obtained (such as concatenating strings, conditional judgments), it is recommended to assign
systemthe value obtained from the tag to a variable, for example{% system siteName with name="SiteName" %}If only to display simply, output directly is more concise. - Debug and checkIf configuration information is not displayed correctly in the template, please first check whether the corresponding settings on the back-end have been saved, and then confirm
nameIs the spelling of the attribute completely correct (case-sensitive). If necessary, clearing the AnQiCMS cache or browser cache may also be helpful.
By flexible applicationsystemLabel, you can manage and display your website information more efficiently and intelligently, allowing the powerful functions of AnQiCMS to be fully utilized in your template.
Frequently Asked Questions (FAQ)
- Q: Why did I set the website logo in the background, but it doesn't display in the template?
<img src="{% system with name="SiteLogo" %}" ...>Why can't the image be displayed?A: This could be due to several reasons: first, please confirm that you have uploaded and saved the Logo image in the background "Global Settings".Next, check the network request to see if the image URL is correct and accessible.Sometimes, browser cache issues can also cause images