Does the `languages` tag in AnQiCMS support any parameter settings?

AnQi CMS, as an enterprise-level content management system, performs well in helping enterprises with global content layout, and "multi-language support" is one of its core advantages. When developing templates for AnQi CMS, we often encounter the need to display or switch the website language, at which point we can't help but mention a key template tag -languages.

AnQiCMS inlanguagesThe core function and design concept of the tag

Directly answer the questions that everyone cares about:In AnQiCMSlanguagesThe tag does not support any parameter settings.

This initially sounds surprising, after all, we are accustomed to many list labels that can be passed throughlimit/categoryId/orderFine-tune parameters for precision control. However, this is not a lack of AnQiCMS features, but rather an embodiment of its design philosophy.languagesThe responsibility of tags is very clear and single:Get the list of all multilingual sites configured in the current system.

ImaginelanguagesThe tag is like a loyal messenger, whose task is not to order dishes in the kitchen (set parameters), but to bring back the list of all ready dishes from the kitchen unchanged (list of multilingual site lists).The development team of AnQiCMS places the definition and management of multilingual sites at a more macro level, namely through the background multi-site management feature to create, configure, and activate different language versions.Once these language sites are set up in the background,languagesThe tags can accurately capture this information.

This 'parameterless' design simplifies the development complexity of the front-end template because you don't 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 make use of this data and display it in a user-friendly manner, such as building a language switcher or generating for SEO.hreflang.

The powerful application of “no parameters” is to utilizelanguagesTag to implement multilingual functionality

ThoughlanguagesThe tag itself has no parameters, but the rich data fields it provides are enough to support various complex language switching and SEO needs. It returns an array object, eachitemRepresents a language site, including the following key fields:

  • LanguageName: The language name of the site (e.g. "Chinese", "English").
  • Language: The ISO code for languages (e.g. 'zh-CN', 'en-US'), often usedhreflangProperty.
  • LanguageEmoji: The Emoji symbol for language (e.g. 🌐).
  • LanguageIcon: Language corresponding icon URL, if configured.
  • Name: The name of the site.
  • Link: Link address of 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 traversinglanguagesThe tag retrieves the list of sites, and we can easily create a language selection menu, allowing users to freely switch between different language versions.

{%- 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 go through{%- languages websites %}Get all language sites and assign them towebsitesVariable. Then, use{%- for item in websites %}Loop through each language site and useitem.LinkGenerate a jump link,item.LanguageIconoritem.LanguageEmojiDisplay the language identifier, as well asitem.LanguageNameDisplay language name. Implemented language switching simply and efficiently.

2. Achieved SEO-friendlyhreflangTag

For multilingual websites,hreflangTags are the key to search engines understanding the association of content in different language versions.It tells the search engine that the specific page has other language versions, thus avoiding duplicate content issues and ensuring that users can access the page most suitable for 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 tag for each configured language site<link rel="alternate" hreflang="xx">to ensure that search engines can correctly identify and index all language versions.item.LinkProvided the complete URL of the corresponding language page, whileitem.Languagethen provided the standard language code.

Deeply understand the multilingual mechanism of AnQiCMS

AnQiCMS is able tolanguagesThe tag is so concise, thanks to its perfect multi-site management function in the AnQiCMS backend. In the AnQiCMS backend, you can:

  1. Configure the default language package in the global settingsThis affects the display of built-in text in the system, but is not directly related to the switching of the front-end language site.
  2. Create independent language sites through the "Multi-site Management" feature.This is a language version that can be considered as an independent website instance, with its own domain name, data storage, and template configuration.languagesThe real source of label information. For example, you can setexample.comas the Chinese main station,en.example.comEnglish sub-sites, which are managed as two independent 'sites' in the AnQiCMS backend.

languagesThe label actually reads these site information defined in the "Multi-site Management" backend and extracts the language-related data from it, for use in the front-end template.This allows template developers to not delve deeply into the specific configuration details of the backend site, but to focus on how to display and make use of the existing language site data.

Summary

Although AnQiCMS'slanguagesThe tag has no parameters set, but that is precisely the cleverness of its design.It focuses on providing all configured multilingual site information, separating complex business logic from the frontend display.Developers only need to go through simpleforLoop to efficiently implement multi-language switching and SEO optimization and other key functions.This clear division of responsibilities ensures the simplicity of the system while also providing sufficient flexibility to meet the operational needs of multilingual websites.


Frequently Asked Questions (FAQ)

Q1: If I want to filter and only display certain languages (such as only displaying Chinese and English), how can I do it with AnQiCMS'slanguagestags?

A1: languagesThe tag itself does not provide filtering parameters. However, you can use the Go language template engine (similar to Django syntax) in the template.{% if %}Logic, while iterating.websitesWhen an array is making a conditional judgment. For example, only show 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 %}

By this method, you can according toitem.Language/item.LanguageNameor other fields for flexible filtering.

Q2:languagesWhat is the location configured in the AnQiCMS backend for obtaining the language site information tag?

A2:These language sites are mainly configured in the "Multi-Site Management" feature of the AnQiCMS backend.Each independent language site is created and managed as a "site", including its domain name, database information, administrator account, and the templates used.languagesThe label reads the information of sites marked with different languages among these configured and enabled sites.

Q3: How to enable multi-language functionality or add a new language site in the AnQiCMS backend?

A3:The feature of enabling multilingual function is not a simple switch, but is realized by configuring multiple independent sites.

  1. First, 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.
  2. To add a switchable language 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.Once created and configured,languagesThe tag can detect and display the new language site on the front end.