How to retrieve and display the system configuration information of the website in the template?

In website operation, we often need to display some global website information, such as website name, Logo, filing number, copyright statement, and even customized contact information or social media links.This information, if directly hardcoded in the template, would require searching and updating each page whenever a modification is needed, which is time-consuming and prone to errors.AnQi CMS provides a very powerful and convenient template tagsystemLabel, allowing these system configuration information to be dynamically retrieved and displayed in the template, greatly enhancing the maintainability and operational efficiency of the website.

systemLabel: Convenient entry point for website information

systemThe tag is a core tool used by Anqi CMS to obtain various configurations from the "Global Function Settings" in the background.By it, you can flexibly call website name, Logo, basic link and a series of important system-level data at any location in the website template.

Its basic usage is very intuitive:{% system 变量名称 with name="字段名称" %}.

here,name="字段名称"Specify the specific system configuration item you want to retrieve, and变量名称It is optional. If you provide a variable name, the value of this configuration item will be stored in this variable, and you can use it in the subsequent code.{{变量名称}}Output; if you do not provide a variable name,systemthe tag will output the configuration value directly to the current position.

in addition to getting the information of the current site,systemLabels also support asiteIdParameters. If you are managing multiple sites and need to call system configurations of other sites, you cansiteIdSpecify the target site. But in most cases, we usually only need to get the information of the current site, so this parameter can be ignored.

Get the commonly used system configuration information

Let's take a look atsystemTags can retrieve specific configurations and how to call them in the template.

Website name (SiteName)

This is the most basic identifier of the website, usually displayed in the browser title bar, next to the Logo, or in the footer.

{# 直接输出网站名称 #}
<div>网站名称:{% system with name="SiteName" %}</div>
{# 将网站名称赋值给变量并输出 #}
<div>网站名称:{% system currentSiteName with name="SiteName" %}{{currentSiteName}}</div>

Website Logo (SiteLogo)

The brand logo of a website, usually a link to an image.

{# 直接输出Logo图片,并使用网站名称作为alt属性,提升SEO #}
<img src="{% system with name="SiteLogo" %}" alt="{% system with name="SiteName" %}" />
{# 将Logo链接赋值给变量,再构建图片标签 #}
{% system siteLogoPath with name="SiteLogo" %}
<img src="{{siteLogoPath}}" alt="{% system with name="SiteName" %}" />

Website filing number (SiteIcp)

According to national regulations, the record information is usually displayed in the footer of the website.

{# 显示备案号,并链接到工信部备案查询平台 #}
<p><a href="https://beian.miit.gov.cn/" rel="nofollow" target="_blank">{% system with name="SiteIcp" %}</a></p>

Copyright content (SiteCopyright)

Footer copyright statement, which can include the year and company name, etc.

{# 直接输出版权信息,注意使用safe过滤器以防HTML内容被转义 #}
<div>{% system with name="SiteCopyright"|safe %}</div>
{# 赋值给变量并输出 #}
{% system copyrightInfo with name="SiteCopyright" %}
<div>{{copyrightInfo|safe}}</div>

The home page address (BaseUrl)

This is the root URL of the website, which is very useful when building absolute links.

{# 获取网站首页地址,用于构建返回首页的链接 #}
<a href="{% system with name="BaseUrl" %}" class="home-link">返回首页</a>

Mobile address of the website (MobileUrl)

If your website has enabled a separate mobile domain (configured in the background "Global Feature Settings"), you can obtain it here.

{# 在PC端判断并提供手机端链接,引导用户切换 #}
{% system mobileSiteUrl with name="MobileUrl" %}
{% if mobileSiteUrl %}
    <a href="{{mobileSiteUrl}}" class="mobile-version-link">访问手机版</a>
{% endif %}

Static file address of the template (TemplateUrl)

Used to link the template directory below, such as CSS, JS, images, and other static resources, ensure the path is correct.

{# 链接模板目录下的样式表 #}
<link href="{% system with name="TemplateUrl" %}/css/style.css" rel="stylesheet">
{# 链接模板目录下的JavaScript文件 #}
<script src="{% system with name="TemplateUrl" %}/js/main.js"></script>

Closed site prompt content (SiteCloseTips)

When the website is in maintenance or closed, the system will display the prompt information configured here.

{# 在网站维护页面显示闭站提示 #}
<div class="maintenance-message">
    <p>{% system with name="SiteCloseTips" %}</p>
</div>

Site language (Language)

Indicates the language used by the current website, often used for<html>label'slangProperty.

{# 在HTML根标签中设置语言属性 #}
<html lang="{% system with name='Language' %}">

Custom parameter

The strength of AnQi CMS lies in its high customizability.In the background "Global Feature Settings", you can add any number of custom parameters to meet the personalized calling needs in the template.For example, you may want to add configuration items such as a 'WeChat official account QR code' or 'help page link'.

Assuming you have created a namedHelpPageUrlThe custom parameter, with a value ofhttps://www.yourdomain.com/help. You can call it like this in the template:

{# 调用自定义的帮助页面链接 #}
<a href="{% system with name="HelpPageUrl" %}">访问帮助中心</a>
{# 将自定义参数赋值给变量 #}
{% system helpLink with name="HelpPageUrl" %}
<p>更多信息请点击:<a href="{{helpLink}}">{{helpLink}}</a></p>

Practical suggestions and flexible application

Rational utilizationsystemTags, which can make your website template more flexible. You can place them in the public header file (such aspartial/header.htmlCalling inSiteName/SiteLogoandTemplateUrlIn the footer file (such aspartial/footer.htmlCalling inSiteIcpandSiteCopyrightManage custom contact information or social media links through custom parameters.This way, once some information needs to be updated, it only needs to be modified once in the background, and all pages that call this information will be automatically synchronized for updates, greatly reducing the cost and risk of manual intervention and errors.

Furthermore,systemThe information retrieved by the label is dynamic, which means that when you change the configuration in the background, the front-end page will immediately reflect these changes (unless there is a caching mechanism involved, but usually just refreshing the page is enough to see them).This is crucial for the daily maintenance of the website and quick response to market changes.

In this way, Anqi CMS not only provides powerful content management capabilities, but also throughsystemA series of flexible template tools, giving website operators full control, making website management unprecedentedly easy and efficient.


Frequently Asked Questions (FAQ)

1. Why didn't the front-end page update immediately after I modified the system settings in the background?The Anqi CMS usually improves website access speed through caching mechanisms.If you have modified the system configuration in the background but the front-end page does not display the new content immediately, it may be because the cache has not been refreshed.Try clearing the browser cache, or find the "Update Cache" feature in the Anqi CMS backend and execute it, you should usually see the latest configuration.

2. In the template usagesystemwhen calling custom parameters with tags,nameHow should the attribute be filled in? nameThe value should be exactly the same as the 'parameter name' you entered when adding custom parameters in the background 'Global Function Settings'. Please note that Anqi CMS is case-sensitive for parameter names and it will automatically convert the input letters to camel case (for example, you inputhelp page urlMay be processed by the system asHelpPageUrl), so make sure the template innamematches the actual parameter name stored on the back end.

3.BaseUrlandTemplateUrlWhat is the difference? When should I use them? BaseUrlis the root address of the website, for examplehttps://www.yourdomain.com/It is mainly used to build absolute links for in-site pages, ensuring that users can be correctly directed to the target page regardless of where they navigate from.TemplateUrlIt is the URL of the current active template directory, for example.https://www.yourdomain.com/template/default/It is mainly used to refer to static resources within the template, such as CSS, JavaScript files, or images, to ensure that these resources can be loaded correctly by the browser. Simply put,BaseUrlIs the basis of website content navigation,TemplateUrlIs the basis of template resource loading.