Anqi CMS multilingual site operation manual: How to use cleverlysystemTag to get 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 network environment.AnQiCMS is an enterprise-level content management system developed based on the Go language, which provides us with great convenience with its powerful multi-site and multi-language support.Today, let's delve deeply into a seemingly simple yet powerful template tag in AnQiCMS-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 Swiss Army knife configuration
In the AnQiCMS template system,systemThe tag plays a role in obtaining the global system configuration information. It is like a multi-functional Swiss Army knife, which can extract various core settings of your website at any time, whether it is the website name, Logo address, or filing number, Base URL, etc., all can be easily obtained through a simple tag.
In most cases, we would use it like this in the templatesystemLabel 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, such asSiteName(Website name),SiteLogo(Website Logo),SiteIcp(Website record number),BaseUrl(Website home page address) etc. These are preset fields that can be found and modified in the background "Global Function Settings".
WithsiteIdUnlock the magic of cross-site configuration.
One of the most prominent advantages of AnQiCMS is its powerful multi-site management capabilities.How to maintain consistency in configuration when you are operating multiple brand websites, sub-sites, or multiple language sites for different language users, or dynamically referencing the configuration of one site from another site, becomes particularly important. At this point,systemAnother key parameter of the tag--siteIdit 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 get the website name, Base URL, and even custom configuration parameters of an English site in its template.This provides infinite possibilities for implementing advanced features such as language switches and cross-site resource references.
Assuming you have a main site (ID 1, Chinese) and an English site (ID 2).Now, we want to display the website name of the English site 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 goes throughsiteId="2"Retrieve the website name of the English site with ID 2 (SiteName) and the basic URL (BaseUrl), and assign them toenglishSiteNameandenglishSiteUrlThese two variables. Subsequently, we can freely use these variables in templates to build cross-site links and display information.
Dynamically build a multilingual switcher
Further, combining the AnQiCMS providedlanguagestags, we can dynamically build a perfect multilingual switcher.languagesThe tag can retrieve a list of all multilingual sites, where each item includes the site ID, language name, language code, and link information. We can uselanguagesLabel loops through all sites and, within the loop, throughsystemLabel and each site'ssiteIdGet its specific website name or Logo to create more personalized and recognizable 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 shows how to usesiteIdGet the specific name of each site, incorporating language icons and Emojis, making the language switching experience more intuitive and friendly.In this way, we can generate a switch in the template of any site that includes information about all language sites, greatly enhancing the user experience and the internationalization of the website.
Application and practice with **
In actual operation,systemLabel collaborationsiteIdThe application scenario is very extensive:
- Unified header/footer:No matter which language site the user visits, the contact information, Logo, or copyright information of the main site can be displayed uniformly in the header or footer, ensuring the consistency of the brand image.
- Cross-site resource loading:If your sites in different languages share some static resources (such as CSS, JS files, or images), you can place these resources under a main site and access them through
systemTag to get the main siteBaseUrlThen, reference these resources to avoid duplicate uploads and management. - SEO optimization:In the setting
hreflangWhile tagginglanguagesTags can provide basic links, but if you need to access specific sites,canonicalURL or a specific language website name as metadata,systemTags can provide precise data support. - Multi-site content recommendation:Imagine recommending selected articles or products from another language site on a certain site
systemTags can help you get basic information about the target site so that you can correctly construct recommendation links.
While usingsystemWhen obtaining cross-site configuration tags, be sure to understand the target site'ssiteIdThis ID is usually found in the "Multi-site Management" list in the AnQiCMS backend. Use it reasonably.siteIdIt can not only simplify template development, but also make your AnQiCMS multi-site operation more flexible and powerful.
Conclusion
AnQiCMS'systemTags, especially combinedsiteIdThe use of parameters, for us to perform multilingual,