AnQi CMS, as an enterprise-level content management system, has an excellent performance in helping enterprises carry out global content layout, and 'multi-language support' is one of its core advantages. When developing templates with AnQi CMS, we often encounter the need to display or switch the website language, at which time it is necessary to mention a key template tag -languages.
AnQiCMS in EnglishlanguagesThe core function and design concept of the tag
Directly answer the most concerned questions of everyone:In AnQiCMSlanguagesThe tag does not support any parameter settings.
This at first glance seems somewhat unexpected, after all we are accustomed to many list labels that can belimit/categoryId/orderParameters are controlled with precision. However, this is not a lack of features in AnQiCMS, but a reflection of its design concept.languagesThe responsibility of the tags is very clear and single:Get the list of all multilingual sites configured in the current system.
Imagine that,languagesTags are like loyal messengers, their task is not to order dishes from the kitchen (set parameters), but to bring back the list of all dishes prepared in the kitchen without any alterations (multilingual site list).The development team of AnQiCMS places the definition and management of multilingual sites at a more macro system level, that is, through the multi-site management feature of the backend to create, configure, and activate different language versions.languagesTags can accurately capture this information without any error.
This “no-parameters” design simplifies the development complexity of front-end templates, as you do not need to worry about how to filter or sort the language list—it always provides a complete, system-defined language set. Your main task is to utilize these data in a user-friendly manner, such as building a language switcher or generating SEO contenthreflangLabel.
The powerful application of 'no parameter': utilizinglanguagesTags to implement multilingual functionality
AlthoughlanguagesThe tag itself does not have any parameters, but the rich data fields it provides are enough to support various complex language switching and SEO requirements. It returns an array object, with eachitemRepresents a language site, including the following keyword fields:
LanguageName: The language name of the site (e.g., “Chinese”, “English”).*Language: 语言的ISO代码(例如“zh-CN”、“en-US”),常用于Englishhreflangproperties.LanguageEmoji: 语言对应的Emoji表情(例如🌐)。LanguageIcon: Language icon URL, if configured.Name: Site name.Link: Link address to the corresponding language site.Remark: Link remark information.Nofollow: Whether it isnofollowLinks, usually used for SEO control.
Let's take a look at how we can cleverly use these fields:
1. Build a language switcher
This is the most common application scenario. By traversinglanguagesLabel acquisition site list, we can easily create a language selection menu to allow users to switch between different language versions freely.
{%- languages websites %}
{%- if websites %}
<div class="language-switcher">
<span>切换语言:</span>
{%- for item in websites %}
<a href="{{item.Link}}" class="language-item">
{%- if item.LanguageIcon %} {# 优先显示图标,如果没有则显示Emoji #}
<img src="{{item.LanguageIcon}}" alt="{{item.LanguageName}}" class="language-icon" />
{%- else %}
<span class="language-emoji">{{item.LanguageEmoji}}</span>
{% endif %}
<span class="language-name">{{item.LanguageName}}</span>
</a>
{%- endfor %}
</div>
{%- endif %}
{%- endLanguages %}
In this code, we first{%- languages websites %}Get all language sites and assign them towebsitesVariable. Next,{%- for item in websites %}loop through each language site and use,item.Linkgenerate jump links,item.LanguageIconoritem.LanguageEmojidisplay language identifiers, as well asitem.LanguageNameDisplay language name. Simply and efficiently implemented the language switching function.
2. Implement SEO-friendlyhreflangtags
For multilingual websites,hreflangLabels are the key for search engines to understand the correlation between different language versions of content.It tells the search engine that there are other language versions of a specific page, thus avoiding duplicate content issues and ensuring that users can access the page best suited to their language or region.languagesTags can help us dynamically generate these tags, placed in the HTML's<head>area:
{%- languages websites %}
{%- for item in websites %}
<link rel="alternate" href="{{item.Link}}" hreflang="{{item.Language}}">
{%- endfor %}
{%- endLanguages %}
This code will generate a for each language site configuration.<link rel="alternate" hreflang="xx">Tags to ensure that search engines can correctly identify and index all language versions.item.LinkProvided the complete URL of the corresponding language page.item.LanguageIt provides the standard language code.
Deeply understand the multilingual mechanism of AnQiCMS.
AnQiCMS can makelanguagesThe label is so concise, thanks to its perfect multi-site management function on the backend. In the AnQiCMS backend, you can:
- Configure the default language package in the global settingsThis affects the display of built-in system text, but is not directly associated with the switch of the front-end language site.
- Create independent language sites through the "Multi-site Management" featureEach language version can be considered as an independent website instance, with its own domain name, data storage, and template configuration. This is
languagesLabel gets the real source of information. For example, you can setexample.comas the Chinese main station,en.example.comFor English sub-site, they are managed as two independent "sites" in AnQiCMS backend.
languagesThe tag actually reads these "site" information defined in the background "Multi-site Management" and extracts the data related to the language, providing it for use in the frontend template.This allows template developers to not need to deeply understand the specific configuration details of the backend site, but to focus on how to display and utilize these existing language site data.
Summary
Although the AnQiCMSlanguagesThe label has no parameters set, but that is exactly the cleverness of its design.It focuses on providing all configured multilingual site information, separating complex business logic from the front-end display.forLoop, to efficiently implement key functions such as multilingual switching and SEO optimization.This clear division of responsibilities ensures the simplicity of the system while providing enough flexibility to meet the operational needs of multilingual websites.
Common Questions (FAQ)
Q1: If I want to filter and display only certain languages (such as only Chinese and English), is there a way to do so in AnQiCMS?languagesCan the tags achieve this?
A1: languagesThe label itself does not provide filtering parameters. However, you can use the Go language template engine (similar to Django syntax) in the template.{% if %}logic, when traversingwebsitesPerforming conditional judgment on the array. For example, only display Chinese and English:
{%- languages websites %}
{%- for item in websites %}
{% if item.Language == "zh-CN" or item.Language == "en-US" %}
<a href="{{item.Link}}">{{item.LanguageName}}</a>
{% endif %}
{%- endfor %}
{%- endLanguages %}
In this way, you can judgeitem.Language/item.LanguageNameor other fields for flexible filtering.
Q2:languagesThe language site information of the label acquisition is configured at which position in the AnQiCMS backend?
A2:These language sites are mainly configured in the "Multi-Site Management" feature of the AnQiCMS backend.Each independent language site will be created and managed as a "site", including its domain name, database information, administrator account, and the templates used.languagesThe label is reading the site information marked with different languages from these configured and enabled sites.
Q3: How to enable multi-language feature or add a new language site in AnQiCMS backend?
A3:Enabling multilingual functionality is not a simple switch, but is achieved by configuring multiple independent sites.
- Firstly, you can set the "default language package" in the "Background Settings" -> "Global Settings".This will affect the language of the system interface and built-in prompts.
- To add a language switchable site, you need to go to "Multi-site Management"Then click 'Add new site'.Here, you need to configure a separate domain (or subdomain), database, and other relevant information for the new language version.When creating a site, there will be an option for you to specify the language of the site.
languagesTags can detect and display this new language site on the frontend.