How to get the current website's system configuration information (such as website name, Logo) in AnQiCMS template?

As an experienced website operation expert, I am happy to discuss with you how to efficiently and flexibly obtain the current website system configuration information in the AnQiCMS template.This is not only the foundation of template development, but also the key to ensuring the unity and maintainability of website information.AnQiCMS as 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 invocation of technical information in the template layer extremely intuitive.

Smart usesystemLabel: The universal key to website information

In the template system of AnQiCMS, you will find an extremely core and powerful tool, which issystemTag.It acts like a '万能钥匙', which can help you easily unlock and display all the core configurations of the website, whether it's the website name, Logo image, or filing information, copyright statement, or even the custom global parameters, all of which can be called through it in the template.

ThissystemThe basic usage of the tag 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 and write it directly as{% system with name="字段名称" %}Here,nameProperties are 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 also the most representative ofsystemConfiguration information and calling methods of the practical value of tags.

Website name (SiteName): Your brand identity

The website name is the basic identity symbol of each website.In the "Global Settingsname="SiteName"To get:

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

{# 将网站名称赋值给一个变量再使用,方便复杂场景 #}
{% system websiteName with name="SiteName" %}
<title>{{ websiteName }} - **内容管理系统</title>

This approach avoids hardcoding the website name in multiple template files. Once the backend is modified, the frontend will also update automatically, greatly improving maintenance efficiency.

Website Logo (SiteLogoVisual representation carrier

The logo is the visual soul of the website.In AnQiCMS backend, you can upload the website's 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 obtained the URL of the Logo image, but also combined the website name as the image'saltProperties, this is a very good practice for SEO and accessibility. At the same time,BaseUrlThe application of tags ensures that the Logo link always points to the homepage of the website, even if the domain changes, and no modification of the template is needed.

Other important global configuration information

In addition to the website name and Logo,systemTags can also help you get 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 copyright information may contain HTML tags (such as links), you may need to cooperate with|safeA filter to ensure correct parsing of HTML content:
    
    {% system copyrightInfo with name="SiteCopyright" %}
    <p>{{ copyrightInfo|safe }}</p>
    
  • Website Home 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>
    
  • Template Static File Address (TemplateUrl)When developing templates, your static resources such as CSS, JavaScript, and images are usually stored in:/public/static/In the directory, and through/templateThe references to various templates under the template folder.TemplateUrlThis will help you build the correct static resource path, ensuring that styles and scripts can be loaded 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)For a multilingual website,<html>tagslangProperty settings are very useful, helping browsers and search engines better understand the language used in the website content:
    
    <html lang="{% system with name="Language" %}">
    

Custom parameters: meet personalized needs

The flexibility of AnQiCMS is also reflected in its ability to allow you to add custom parameters in the "Global Settings" backend. For example, you may have added a parameter named "Customer Service Phone Number", which参数名setCustomerPhoneThen in the template, you can access it just like built-in fields:

<p>客服热线:{% system with name="CustomerPhone" %}</p>

This allows AnQiCMS to easily adapt to various complex website operation needs without modifying the core code.

Tips for practice

  1. Call in a multi-site environmentIf you have managed multiple sites in AnQiCMS and want to callother sitesin the template of the current sitesystemtags support ansiteIdParameter. For example, to get the site with ID2, you can write the site name like this:{% system with name="SiteName" siteId="2" %}. This is very useful when building cross-site content or integrating services.
  2. 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 assignsystemthe value obtained from the label to a variable, for example{% system siteName with name="SiteName" %}If only for simple display, direct output is more concise.
  3. Debugging and checkingIf configuration information is not displayed correctly in the template, please first check if the corresponding settings on the back-end have been saved, and then confirm.nameIs the spelling of the attribute completely correct (case-sensitive)? Cleaning the cache of AnQiCMS or the browser cache may also be helpful if necessary.

By using flexibilitysystemTags, you will be able to manage and display your website information more efficiently and intelligently, allowing the powerful functions of AnQiCMS to be fully realized in your template.


Common Questions (FAQ)

  1. 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 may be caused by several reasons: first, please confirm that you have uploaded and saved the Logo image in the "Global Settings" in the background.Then, check the network request to see if the image URL is correct and accessible.