How to get the global configuration information of AnQiCMS template, such as the website name and logo?

In AnQiCMS template, cleverly obtain the global configuration of the website to make your website more flexible

When designing or maintaining the AnQiCMS website template, we often encounter a need to display unified global information on various pages of the website, such as the name of the website, logo, filing number, or custom contact information, etc.Manually adding this information to each page is not only inefficient, but it also takes a lot of time and effort to update once it needs to be modified.systemTags, allowing you to easily access these global system configurations in templates, thereby building more flexible and easy-to-maintain websites.

Core Method: System Tags(systemTag)

AnQiCMS template uses a syntax similar to the Django template engine, for accessing global configuration information,systemTags are your core tool. It can directly access the various data you configure in the background "Global Feature Settings".

systemBasic usage of tags

systemThe general syntax of the tag is very intuitive: you can specifynameparameters to get specific configuration items.

{% system 变量名称 with name="字段名称" %}

here,变量名称It is optional, you can omit it if you want to output the result directly inside the tag; you can define one if you want to assign the obtained value to a variable for later use变量名称.字段名称The English identifier of the specific configuration item you want to get.

Next, let's see how to use this tag with some common examples:

To get the website name (SiteName)

The website name is an indispensable identifier for each website. In the AnQiCMS background "Global Function Settings", the "website name" you set can be accessed throughSiteNameThis field name is used to obtain.

{# 直接输出网站名称 #}
<h1>{% system with name="SiteName" %}</h1>

{# 将网站名称赋值给一个变量,然后使用 #}
{% system siteName with name="SiteName" %}
<p>欢迎来到 {{ siteName }}!</p>

Get the website logo (SiteLogo)

The website logo is also a key element of the brand image of the website. The address of the website logo image uploaded in the "Global Function Settings" can be obtained throughSiteLogothe field.

{# 直接输出网站LOGO,同时利用网站名称作为图片的alt属性,有利于SEO #}
<img src="{% system with name="SiteLogo" %}" alt="{% system with name="SiteName" %}" />

{# 将LOGO图片地址赋值给变量,并结合网站名称 #}
{% system siteLogo with name="SiteLogo" %}
{% system siteName with name="SiteName" %}
<a href="/">
    <img src="{{ siteLogo }}" alt="{{ siteName }} Logo" />
</a>

Other commonly used global information

Besides the website name and LOGO,systemtags can also get many other useful global configurations:

  • Website filing number (SiteIcp):
    
    <p><a href="https://beian.miit.gov.cn/" rel="nofollow" target="_blank">{% system with name="SiteIcp" %}</a></p>
    
  • Copyright content (SiteCopyright)This is usually used at the bottom of the website to display copyright statements. If the copyright information in the background contains HTML tags (such as links), remember to use|safeA filter that allows the template to render HTML correctly rather than outputting it as plain text.
    
    {% system copyrightInfo with name="SiteCopyright" %}
    <p>{{ copyrightInfo|safe }}</p>
    
  • The home page address (BaseUrl):
    
    <a href="{% system with name="BaseUrl" %}">返回首页</a>
    
  • Static file address of the template (TemplateUrl)This is very useful, it points to the current template folder./public/static/Directory, convenient for you to introduce CSS, JavaScript and other static resources.
    
    <link href="{% system with name="TemplateUrl" %}/css/style.css" rel="stylesheet">
    <script src="{% system with name="TemplateUrl" %}/js/main.js"></script>
    
  • Site language (Language): Get the language code of the current site, commonly used in HTML'slangProperty.
    
    <html lang="{% system with name='Language' %}">
    

Custom parameter: Extend your configuration

AnQiCMS's 'Global Function Settings' also allows you to add custom parameters.This means you can create any global configuration item according to your specific needs.For example, you may want to add a "WeChat customer service number" or "online customer service link" and call it in the template.

  1. Add custom parameter in the backgroundEnter the "Backend Settings" -> "Global Function Settings" page of the AnQiCMS backend. At the bottom of the page, find the "Custom Setting Parameters", click "Add Custom Parameter", and fill in the parameter name (for exampleWechatServiceNo) and parameter value.

  2. Call custom parameters in the template. Once saved, you can usesystemtags, to get their values by the parameter names you define.

    {# 假设您在后台自定义了一个名为 "WechatServiceNo" 的参数 #}
    <p>微信客服:{% system with name="WechatServiceNo" %}</p>
    
    
    {# 假设您自定义了一个名为 "AnalyticsCode" 的参数,通常会包含HTML/JS代码 #}
    {% system analyticsScript with name="AnalyticsCode" %}
    {% if analyticsScript %}
    {{ analyticsScript|safe }}
    {% endif %}
    

Applied: Build website header and footer

BysystemTags, you can easily build common website modules such as headers and footers, ensuring that the content of these modules remains consistent throughout the site.

{# partial/header.html #}
<header class="site-header">
    <div class="container">
        <div class="logo">
            <a href="{% system with name="BaseUrl" %}">
                <img src="{% system with name="SiteLogo" %}" alt="{% system with name="SiteName" %}" />
            </a>
        </div>
        <nav class="main-nav">
            {# 导航列表通常使用navList标签,这里仅作示意 #}
            <ul>
                <li><a href="{% system with name="BaseUrl" %}">首页</a></li>
                {# ... 其他导航项 ... #}
            </ul>
        </nav>
    </div>
</header>

{# partial/footer.html #}
<footer class="site-footer">
    <div class="container">
        <p>{% system copyrightInfo with name="SiteCopyright" %}{{ copyrightInfo|safe }}</p>
        <p>备案号:<a href="https://beian.miit.gov.cn/" rel="nofollow" target="_blank">{% system with name="SiteIcp" %}</a></p>
        <p>联系电话:{% contact with name="Cellphone" %}</p>
        <p>网站地址:<a href="{% system with name="BaseUrl" %}">{% system with name="BaseUrl" %}</a></p>
    </div>
</footer>

Then simply include these common segments in your page template:

{% include "partial/header.html" %}

<main class="site-content">
    {# 页面具体内容 #}
</main>

{% include "partial/footer.html" %}

This way, whether you need to modify the website name, logo, or copyright information, you only need to operate once in the "Global Function Settings" of AnQiCMS backend, and the template will automatically synchronize the update, greatly improving the website maintenance efficiency.

Tips and **Practice

  • Multi-site environment:siteIdParameterIf you have created multiple sites through the multi-site management feature of AnQiCMS and need to obtain the global configuration of other sites in the template of a certain site,systemTags also supportsiteIdParameters. For example{% system with name="SiteName" siteId="2" %}It will retrieve the website name of the site with ID 2. However, for the global configuration of the current site, it is usually not necessary to specifysiteId.
  • Variable naming and case: Please notenameThe field name (such asSiteName/SiteLogo) is case-sensitive and must match the definitions in the AnQiCMS backend and documentation.
  • Backend Management: Global SettingsAll these callable global configurations can be managed and updated in "Background Settings" -> "Global Feature Settings". Familiarizing yourself with this area will help you make better use ofsystem.

By flexible applicationsystemLabel, you can easily manage and display the global configuration information of the AnQiCMS website, making your template development and website operation work more efficient and convenient.


Frequently Asked Questions (FAQ)

1. Why is my website name or logo not displayed in the template, or displayed incorrectly?

First, please check whether the "Background Settings" -> "Global Function Settings" of AnQiCMS backend has correctly filled in the "Website Name" or uploaded the "Website Logo".If the background information is blank, the template naturally cannot retrieve the content.nameAre the parameter values correct, for example?SiteNameorSiteLogoAnd the case should be matched exactly. Finally, clear the browser cache and AnQiCMS system cache (through the "Update Cache" function in the background).