How to retrieve configuration information for different multi-language sites using the `system` tag?

Multi-language Site Operation Manual for AnQi CMS: Make good use ofsystemtags to retrieve configuration information

As a senior website operator, we know that efficient content management and flexible configuration adjustment are the key to success in a changing online environment.AnQiCMS as an enterprise-level content management system developed in Go language, with its powerful multi-site and multi-language support, provides us with great convenience.systemEspecially how to cleverly use it to obtain configuration information of different multilingual sites, thereby providing strong support for our content operation and global layout.

systemLabel: Your configuration Swiss Army knife

In the template system of AnQiCMS,systemTags play the role of obtaining system global configuration information.It's like a multi-functional Swiss Army knife that can extract all kinds of core settings of your website at any time and place, whether it's the website name, logo address, or filing number, Base URL, etc., all can be easily obtained with a simple tag.

Generally, we would use it like this in the template:systemLabel to get the current website configuration:

{# 获取当前站点的网站名称 #}
<div>网站名称:{% system with name="SiteName" %}</div>

{# 获取当前站点的Logo图片地址 #}
<img src="{% system with name="SiteLogo" %}" alt="{% system with name="SiteName" %}" />

Here,nameParameters are the specific configuration items we specify to retrieve, such asSiteName[Website Name],SiteLogo[Website Logo],SiteIcp[Website Record Number],BaseUrl(Website homepage address) etc. These are preset fields that can be found and modified in the 'Global Function Settings' backend.

With the help ofsiteId, unlock the magic of cross-site configuration

One of the most prominent advantages of AnQiCMS is its powerful multi-site management capability.How to maintain consistency in configuration when operating multiple brand websites, sub-sites, or multiple language sites for different language users, or when dynamically referencing the configuration of one site within another, becomes particularly important.systemThe other key parameter of the tag is-siteIdand it comes in handy.

siteIdThe parameter allows you to specify the ID of the specific site to retrieve configuration information.This means that even if you are currently visiting a Chinese site, you can still obtain the site name, Base URL, and even custom configuration parameters in the template of an English site.This provides limitless possibilities for implementing advanced features such as language switchers and cross-site resource references.

Assume you have a main site (ID 1, in Chinese) and an English site (ID 2).Now, we want to display the English site name in the footer of the Chinese site and provide a link to the English site.

{# 在中文站点模板中,获取英文站点的网站名称 #}
{% system englishSiteName with name="SiteName" siteId="2" %}
{% system englishSiteUrl with name="BaseUrl" siteId="2" %}

<p>访问我们的英文网站:<a href="{{ englishSiteUrl }}">{{ englishSiteName }}</a></p>

This code first retrieves the latest 5 articles bysiteId="2"We retrieved the site name of the English site with ID 2SiteName) and the base URLBaseUrl, and assigned them toenglishSiteNameandenglishSiteUrlThese two variables. Then, we can freely use these variables in the template to build cross-site links and display information.

Dynamically build a multi-language switcher

Furthermore, combining the provided by AnQiCMS,languagestags, we can dynamically build a perfect multilingual switcher.languagesLabels can retrieve the list of all multilingual sites, and each item in the list includes the site ID, language name, language code, and link information. We can utilizelanguagesLabel loops through all sites, and within the loop,systemLabel and each site's,siteIdGet the specific website name or Logo, thereby creating more personalized and identifiable language switching options.

{%- languages allSites %}
{%- if allSites %}
<nav class="language-switcher">
    <span>切换语言:</span>
    {%- for siteItem in allSites %}
        {# 针对每个语言站点,通过其ID获取其网站名称 #}
        {% system currentSiteName with name="SiteName" siteId=siteItem.Id %}
        <a href="{{siteItem.Link}}" lang="{{siteItem.Language}}" aria-label="切换到 {{ currentSiteName }}">
            {%- if siteItem.LanguageIcon %}
            <img src="{{siteItem.LanguageIcon}}" alt="{{siteItem.LanguageName}} Logo" width="20" height="15" />
            {%- else %}
            {{siteItem.LanguageEmoji}}
            {% endif %}
            {{ currentSiteName }}
        </a>
    {%- endfor %}
</nav>
{%- endif %}
{%- endlanguages %}

This example not only demonstrates how to usesiteIdGet the specific name of each site, incorporating language icons and Emoji, making the language switching experience more intuitive and friendly.In this way, we can generate a switcher containing information about sites in all languages within any site's template, greatly enhancing the user experience and the internationalization level of the website.

Application and **Practice in Reality

In actual operation,systemlabel combined withsiteIdThe application scenarios are very extensive:

  • Unified header/page footer:Regardless of which language site the user visits, contact information, Logo, or copyright information of the main site can be uniformly displayed in the header or footer, ensuring consistency of the brand image.
  • Cross-site resource loading:If your different language sites share some static resources (such as CSS, JS files or images), you can store these resources under a main site and accesssystemLabel to get the main site.BaseUrlThen, reference these resources to avoid repeated uploading and management.
  • [en] SEO Optimization:In the settingshreflangWhen labeling, althoughlanguagesLabels can provide basic links, but if you need to get specific sitescanonicalURL or a specific language website name as metadata,systemTags can provide precise data support.
  • Multi-site content recommendation:Imagine recommending curated articles or products from another language site on a certain site.systemTags can help you obtain basic information about the target site so that you can correctly construct recommendation links.

When usingsystemPlease make sure you understand the cross-site configuration when fetching the labelsiteIdThis ID is usually found in the 'Multi-site Management' list in the AnQiCMS backend. Make good use of it.siteIdIt can not only simplify template development, but also make your AnQiCMS multi-site operation more flexible and powerful.

Concluding remarks

AnQiCMSsystemTags, especially when combinedsiteIdParameter usage, for us to perform multi-language,